Skip to content
Merged
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
23 changes: 14 additions & 9 deletions scripts/ccpp_capgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from framework_env import parse_command_line
from host_cap import write_host_cap
from host_model import HostModel
from metadata_table import parse_metadata_file, SCHEME_HEADER_TYPE
from metadata_table import parse_metadata_file, register_ddts, SCHEME_HEADER_TYPE
from parse_tools import init_log, set_log_level, context_string
from parse_tools import register_fortran_ddt_name
from parse_tools import CCPPError, ParseInternalError
Expand Down Expand Up @@ -468,15 +468,15 @@ def duplicate_item_error(title, filename, itype, orig_item):
raise CCPPError(errmsg.format(**edict))

###############################################################################
def parse_host_model_files(host_filenames, host_name, run_env):
def parse_host_model_files(host_filenames, host_name, run_env,
known_ddts=list()):
###############################################################################
"""
Gather information from host files (e.g., DDTs, registry) and
return a host model object with the information.
"""
header_dict = {}
table_dict = {}
known_ddts = list()
logger = run_env.logger
for filename in host_filenames:
logger.info('Reading host model data from {}'.format(filename))
Expand Down Expand Up @@ -524,15 +524,15 @@ def parse_host_model_files(host_filenames, host_name, run_env):
return host_model

###############################################################################
def parse_scheme_files(scheme_filenames, run_env, skip_ddt_check=False):
def parse_scheme_files(scheme_filenames, run_env, skip_ddt_check=False,
known_ddts=list()):
###############################################################################
"""
Gather information from scheme files (e.g., init, run, and finalize
methods) and return resulting dictionary.
"""
table_dict = {} # Duplicate check and for dependencies processing
header_dict = {} # To check for duplicates
known_ddts = list()
logger = run_env.logger
for filename in scheme_filenames:
logger.info('Reading CCPP schemes from {}'.format(filename))
Expand Down Expand Up @@ -637,15 +637,20 @@ def capgen(run_env, return_db=False):
if run_env.generate_docfiles:
raise CCPPError("--generate-docfiles not yet supported")
# end if
# First up, handle the host files
host_model = parse_host_model_files(host_files, host_name, run_env)
# The host model may depend on suite DDTs
scheme_ddts = register_ddts(scheme_files)
# Handle the host files
host_model = parse_host_model_files(host_files, host_name, run_env,
known_ddts=scheme_ddts)
# Next, parse the scheme files
# We always need to parse the constituent DDTs
const_prop_mod = os.path.join(src_dir, "ccpp_constituent_prop_mod.meta")
if const_prop_mod not in scheme_files:
scheme_files= [const_prop_mod] + scheme_files
scheme_files = [const_prop_mod] + scheme_files
# end if
scheme_headers, scheme_tdict = parse_scheme_files(scheme_files, run_env)
host_ddts = register_ddts(host_files)
Comment thread
dustinswales marked this conversation as resolved.
scheme_headers, scheme_tdict = parse_scheme_files(scheme_files, run_env,
known_ddts=host_ddts)
if run_env.verbose:
ddts = host_model.ddt_lib.keys()
if ddts:
Expand Down
9 changes: 7 additions & 2 deletions scripts/ccpp_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,13 @@ def __init__(self, sdfs, host_model, scheme_headers, run_env):
run_env, ddts=all_ddts)
for header in [d for d in scheme_headers if d.header_type != 'ddt']:
if header.header_type != 'scheme':
errmsg = "{} is an unknown CCPP API metadata header type, {}"
raise CCPPError(errmsg.format(header.title, header.header_type))
if header.header_type == 'module':
errmsg = f"{header.title} is a module metadata header type."
errmsg+=" This is not an allowed CCPP scheme header type."
else:
errmsg = f"{header.title} is an unknown CCPP API metadata header type, {header.header_type}"
# end if
raise CCPPError(errmsg)
# end if
func_id, _, match_trans = \
CCPP_STATE_MACH.function_match(header.title)
Expand Down
285 changes: 176 additions & 109 deletions scripts/metadata_table.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions scripts/parse_tools/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ def __init__(self, linenum=None, filename=None, context=None):
self.__linenum = linenum
self.__filename = filename

def default_module_name(self):
"""Return a default module for this file"""
return os.path.splitext(os.path.basename(self.filename))[0]

@property
def line_num(self):
"""Return the current line"""
Expand Down
7 changes: 3 additions & 4 deletions scripts/suite_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2482,12 +2482,11 @@ def write(self, outfile, host_arglist, indent, const_mod,
# end for
# Look for any DDT types
call_vars = self.call_list.variable_list()
self._ddt_library.write_ddt_use_statements(call_vars, outfile,
indent+1, pad=modmax)
decl_vars = ([x[0] for x in subpart_allocate_vars.values()] +
all_vars = ([x[0] for x in subpart_allocate_vars.values()] +
[x[0] for x in subpart_scalar_vars.values()] +
[x[0] for x in subpart_optional_vars.values()])
self._ddt_library.write_ddt_use_statements(decl_vars, outfile,
all_vars.extend(call_vars)
self._ddt_library.write_ddt_use_statements(all_vars, outfile,
indent+1, pad=modmax)
outfile.write('', 0)
# Write out dummy arguments
Expand Down
4 changes: 3 additions & 1 deletion test/ddthost_test/make_ddt.F90
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ end subroutine make_ddt_run
!> \section arg_table_make_ddt_init Argument Table
!! \htmlinclude arg_table_make_ddt_init.html
!!
subroutine make_ddt_init(nbox, vmr, errmsg, errflg)
subroutine make_ddt_init(nbox, ccpp_info, vmr, errmsg, errflg)
use host_ccpp_ddt, only: ccpp_info_t

! Dummy arguments
integer, intent(in) :: nbox
type(ccpp_info_t), intent(in) :: ccpp_info
type(vmr_type), intent(out) :: vmr
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg
Expand Down
5 changes: 5 additions & 0 deletions test/ddthost_test/make_ddt.meta
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
units = count
dimensions = ()
intent = in
[ ccpp_info ]
standard_name = host_standard_ccpp_type
type = ccpp_info_t
dimensions = ()
intent = in
[ vmr ]
standard_name = volume_mixing_ratio_ddt
dimensions = ()
Expand Down
2 changes: 2 additions & 0 deletions test/ddthost_test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ suite_list="ddt_suite;temp_suite"
required_vars_ddt="ccpp_error_code,ccpp_error_message,horizontal_dimension"
required_vars_ddt="${required_vars_ddt},horizontal_loop_begin"
required_vars_ddt="${required_vars_ddt},horizontal_loop_end"
required_vars_ddt="${required_vars_ddt},host_standard_ccpp_type"
required_vars_ddt="${required_vars_ddt},model_times"
required_vars_ddt="${required_vars_ddt},number_of_model_times"
required_vars_ddt="${required_vars_ddt},surface_air_pressure"
input_vars_ddt="horizontal_dimension"
input_vars_ddt="${input_vars_ddt},horizontal_loop_begin"
input_vars_ddt="${input_vars_ddt},horizontal_loop_end"
input_vars_ddt="${input_vars_ddt},host_standard_ccpp_type"
input_vars_ddt="${input_vars_ddt},model_times,number_of_model_times"
input_vars_ddt="${input_vars_ddt},surface_air_pressure"
output_vars_ddt="ccpp_error_code,ccpp_error_message"
Expand Down
10 changes: 6 additions & 4 deletions test/ddthost_test/test_host.F90
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,11 @@ program test
'ccpp_error_code ', &
'ccpp_error_message ' /)

character(len=cm), target :: test_invars2(3) = (/ &
character(len=cm), target :: test_invars2(4) = (/ &
'model_times ', &
'number_of_model_times ', &
'surface_air_pressure ' /)
'surface_air_pressure ', &
'host_standard_ccpp_type ' /)

character(len=cm), target :: test_outvars2(5) = (/ &
'ccpp_error_code ', &
Expand All @@ -398,12 +399,13 @@ program test
'surface_air_pressure ', &
'number_of_model_times ' /)

character(len=cm), target :: test_reqvars2(5) = (/ &
character(len=cm), target :: test_reqvars2(6) = (/ &
'model_times ', &
'number_of_model_times ', &
'surface_air_pressure ', &
'ccpp_error_code ', &
'ccpp_error_message ' /)
'ccpp_error_message ', &
'host_standard_ccpp_type ' /)
type(suite_info) :: test_suites(2)
logical :: run_okay

Expand Down
3 changes: 2 additions & 1 deletion test/ddthost_test/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
_SUITE_LIST = ["ddt_suite", "temp_suite"]
_INPUT_VARS_DDT = ["model_times", "number_of_model_times",
"horizontal_loop_begin", "horizontal_loop_end",
"surface_air_pressure", "horizontal_dimension"]
"surface_air_pressure", "horizontal_dimension",
"host_standard_ccpp_type"]
_OUTPUT_VARS_DDT = ["ccpp_error_code", "ccpp_error_message", "model_times",
"number_of_model_times", "surface_air_pressure"]
_REQUIRED_VARS_DDT = _INPUT_VARS_DDT + _OUTPUT_VARS_DDT
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/test_metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_bad_table_key(self):
_ = parse_metadata_file(filename, known_ddts, self._DUMMY_RUN_ENV)

#print("The exception is", context.exception)
emsg = "Invalid metadata table start property, 'something', at "
emsg = "Invalid metadata table start property, 'banana', at "
self.assertTrue(emsg in str(context.exception))

def test_bad_line_split(self):
Expand Down
2 changes: 1 addition & 1 deletion test/var_compatibility_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ get_filename_component(CCPP_ROOT "${TEST_ROOT}" DIRECTORY)
#
#------------------------------------------------------------------------------
LIST(APPEND SCHEME_FILES "var_compatibility_files.txt")
LIST(APPEND HOST_FILES "test_host_data" "test_host_mod")
LIST(APPEND HOST_FILES "test_host_data" "test_host_mod")
LIST(APPEND SUITE_FILES "var_compatibility_suite.xml")
# HOST is the name of the executable we will build.
# We assume there are files ${HOST}.meta and ${HOST}.F90 in CMAKE_SOURCE_DIR
Expand Down
6 changes: 3 additions & 3 deletions test/var_compatibility_test/effr_pre.F90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!Test unit conversions for intent in, inout, out variables
!

module effr_pre
module mod_effr_pre

use ccpp_kinds, only: kind_phys

Expand Down Expand Up @@ -56,5 +56,5 @@ subroutine effr_pre_run( effrr_inout, scalar_var, errmsg, errflg)
endif

end subroutine effr_pre_run
end module effr_pre

end module mod_effr_pre
1 change: 1 addition & 0 deletions test/var_compatibility_test/effr_pre.meta
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ccpp-table-properties]
name = effr_pre
type = scheme
module_name = mod_effr_pre
dependencies =
########################################################################
[ccpp-arg-table]
Expand Down
23 changes: 23 additions & 0 deletions test/var_compatibility_test/module_rad_ddt.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module mod_rad_ddt
USE ccpp_kinds, ONLY: kind_phys
implicit none

public ty_rad_lw, ty_rad_sw

!> \section arg_table_ty_rad_lw Argument Table
!! \htmlinclude arg_table_ty_rad_lw.html
!!
type ty_rad_lw
real(kind_phys) :: sfc_up_lw
real(kind_phys) :: sfc_down_lw
end type ty_rad_lw

!> \section arg_table_ty_rad_sw Argument Table
!! \htmlinclude arg_table_ty_rad_sw.html
!!
type ty_rad_sw
real(kind_phys) :: sfc_up_sw
real(kind_phys) :: sfc_down_sw
end type ty_rad_sw

end module mod_rad_ddt
40 changes: 40 additions & 0 deletions test/var_compatibility_test/module_rad_ddt.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[ccpp-table-properties]
name = ty_rad_lw
type = ddt
dependencies =
module_name = mod_rad_ddt
[ccpp-arg-table]
name = ty_rad_lw
type = ddt
[ sfc_up_lw ]
standard_name = surface_upwelling_longwave_radiation_flux
units = W m2
dimensions = ()
type = real
kind = kind_phys
[ sfc_down_lw ]
standard_name = surface_downwelling_longwave_radiation_flux
units = W m2
dimensions = ()
type = real
kind = kind_phys

[ccpp-table-properties]
name = ty_rad_sw
type = ddt
module_name = mod_rad_ddt
[ccpp-arg-table]
name = ty_rad_sw
type = ddt
[ sfc_up_sw ]
standard_name = surface_upwelling_shortwave_radiation_flux
units = W m2
dimensions = ()
type = real
kind = kind_phys
[ sfc_down_sw ]
standard_name = surface_downwelling_shortwave_radiation_flux
units = W m2
dimensions = ()
type = real
kind = kind_phys
35 changes: 35 additions & 0 deletions test/var_compatibility_test/rad_lw.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module rad_lw
use ccpp_kinds, only: kind_phys
use mod_rad_ddt, only: ty_rad_lw

implicit none
private

public :: rad_lw_run

contains

!> \section arg_table_rad_lw_run Argument Table
!! \htmlinclude arg_table_rad_lw_run.html
!!
subroutine rad_lw_run(ncol, fluxLW, errmsg, errflg)

integer, intent(in) :: ncol
type(ty_rad_lw), intent(inout) :: fluxLW(:)
character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg

! Locals
integer :: icol

errmsg = ''
errflg = 0

do icol=1,ncol
fluxLW(icol)%sfc_up_lw = 300._kind_phys
fluxLW(icol)%sfc_down_lw = 50._kind_phys
enddo

end subroutine rad_lw_run

end module rad_lw
35 changes: 35 additions & 0 deletions test/var_compatibility_test/rad_lw.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[ccpp-table-properties]
name = rad_lw
type = scheme
dependencies = module_rad_ddt.F90
[ccpp-arg-table]
name = rad_lw_run
type = scheme
[ ncol ]
standard_name = horizontal_loop_extent
type = integer
units = count
dimensions = ()
intent = in
[fluxLW]
standard_name = longwave_radiation_fluxes
long_name = longwave radiation fluxes
units = W m-2
dimensions = (horizontal_loop_extent)
type = ty_rad_lw
intent = inout
[ errmsg ]
standard_name = ccpp_error_message
long_name = Error message for error handling in CCPP
units = none
dimensions = ()
type = character
kind = len=512
intent = out
[ errflg ]
standard_name = ccpp_error_code
long_name = Error flag for error handling in CCPP
units = 1
dimensions = ()
type = integer
intent = out
Loading