From 48bcb754dff9f0f4dc89c06773253f2b4df36942 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Mon, 3 Jan 2022 19:32:38 -0700 Subject: [PATCH 1/3] Add nested subroutine using 'contains' to temp_calc_adjust_run --- test/capgen_test/temp_calc_adjust.F90 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/capgen_test/temp_calc_adjust.F90 b/test/capgen_test/temp_calc_adjust.F90 index 2094ecec..670fc5cf 100644 --- a/test/capgen_test/temp_calc_adjust.F90 +++ b/test/capgen_test/temp_calc_adjust.F90 @@ -33,7 +33,18 @@ SUBROUTINE temp_calc_adjust_run(nbox, timestep, temp_level, temp_calc, & errmsg = '' errflg = 0 - temp_calc = 1.0_kind_phys + call temp_calc_adjust_nested_subroutine(temp_calc) + + CONTAINS + + ELEMENTAL SUBROUTINE temp_calc_adjust_nested_subroutine(temp) + + REAL(kind_phys), intent(out) :: temp + !------------------------------------------------------------- + + temp = 1.0_kind_phys + + END SUBROUTINE temp_calc_adjust_nested_subroutine END SUBROUTINE temp_calc_adjust_run From ef7a984ba4fee39d06dd53a859fb0ada85a6fe15 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Mon, 3 Jan 2022 19:33:16 -0700 Subject: [PATCH 2/3] Fix parsing of CCPP schemes that contain nested subroutines in 'contains' section --- scripts/fortran_tools/parse_fortran_file.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/fortran_tools/parse_fortran_file.py diff --git a/scripts/fortran_tools/parse_fortran_file.py b/scripts/fortran_tools/parse_fortran_file.py old mode 100644 new mode 100755 index 9082f614..4f914d29 --- a/scripts/fortran_tools/parse_fortran_file.py +++ b/scripts/fortran_tools/parse_fortran_file.py @@ -615,6 +615,7 @@ def parse_scheme_metadata(statements, pobj, spec_name, table_name, run_env): # Find the subroutine line, should be first executable statement inpreamble = False insub = True + seen_contains = False if run_env.logger and run_env.logger.isEnabledFor(logging.DEBUG): ctx = context_string(pobj, nodir=True) msg = "Parsing specification of {}{}" @@ -629,6 +630,9 @@ def parse_scheme_metadata(statements, pobj, spec_name, table_name, run_env): esmatch = _END_SUBROUTINE_RE.match(statement) pmatch = _ENDMODULE_RE.match(statement) asmatch = _ARG_TABLE_START_RE.match(statement) + seen_contains = seen_contains or is_contains_statement(statement, insub) + if seen_contains: + inpreamble = False if asmatch is not None: # We have run off the end of something, hope that is okay # Put this statement back for the caller to deal with @@ -642,7 +646,7 @@ def parse_scheme_metadata(statements, pobj, spec_name, table_name, run_env): insub = False break # End if - if smatch is not None: + if smatch is not None and not seen_contains: scheme_name = smatch.group(1) inpreamble = scheme_name.lower() == table_name.lower() if inpreamble: @@ -674,14 +678,16 @@ def parse_scheme_metadata(statements, pobj, spec_name, table_name, run_env): # End for psrc = ParseSource(scheme_name, 'scheme', pobj) # End if - elif inpreamble: + elif inpreamble or seen_contains: # Process a preamble statement (use or argument declaration) - if esmatch is not None: + if esmatch is not None and scheme_name == esmatch.group(1): inpreamble = False + seen_contains = False insub = False - elif ((not is_comment_statement(statement)) and - (not parse_use_statement(statement, run_env)) and - is_dummy_argument_statement(statement)): + elif (inpreamble and + ((not is_comment_statement(statement)) and + (not parse_use_statement(statement, run_env)) and + is_dummy_argument_statement(statement))): dvars = parse_fortran_var_decl(statement, psrc, run_env) for var in dvars: lname = var.get_prop_value('local_name').lower() From 5c4d312267286523bab03313ff1357710ae953d3 Mon Sep 17 00:00:00 2001 From: Steve Goldhaber Date: Tue, 4 Jan 2022 13:45:02 -0700 Subject: [PATCH 3/3] Do not require label on end subroutine statement --- scripts/fortran_tools/parse_fortran_file.py | 3 ++- test/capgen_test/temp_calc_adjust.F90 | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/fortran_tools/parse_fortran_file.py b/scripts/fortran_tools/parse_fortran_file.py index 4f914d29..f37b3377 100755 --- a/scripts/fortran_tools/parse_fortran_file.py +++ b/scripts/fortran_tools/parse_fortran_file.py @@ -633,6 +633,7 @@ def parse_scheme_metadata(statements, pobj, spec_name, table_name, run_env): seen_contains = seen_contains or is_contains_statement(statement, insub) if seen_contains: inpreamble = False + # End if if asmatch is not None: # We have run off the end of something, hope that is okay # Put this statement back for the caller to deal with @@ -680,7 +681,7 @@ def parse_scheme_metadata(statements, pobj, spec_name, table_name, run_env): # End if elif inpreamble or seen_contains: # Process a preamble statement (use or argument declaration) - if esmatch is not None and scheme_name == esmatch.group(1): + if esmatch is not None: inpreamble = False seen_contains = False insub = False diff --git a/test/capgen_test/temp_calc_adjust.F90 b/test/capgen_test/temp_calc_adjust.F90 index 670fc5cf..61c466f2 100644 --- a/test/capgen_test/temp_calc_adjust.F90 +++ b/test/capgen_test/temp_calc_adjust.F90 @@ -28,12 +28,16 @@ SUBROUTINE temp_calc_adjust_run(nbox, timestep, temp_level, temp_calc, & integer, intent(out) :: errflg !---------------------------------------------------------------- - integer :: col_index + integer :: col_index + real(kind_phys) :: bar = 1.0_kind_phys errmsg = '' errflg = 0 call temp_calc_adjust_nested_subroutine(temp_calc) + if (check_foo()) then + call foo(bar) + end if CONTAINS @@ -46,7 +50,17 @@ ELEMENTAL SUBROUTINE temp_calc_adjust_nested_subroutine(temp) END SUBROUTINE temp_calc_adjust_nested_subroutine - END SUBROUTINE temp_calc_adjust_run + SUBROUTINE foo(bar) + REAL(kind_phys), intent(inout) :: bar + bar = bar + 1.0_kind_phys + + END SUBROUTINE + + logical function check_foo() + check_foo = .true. + end function check_foo + + END SUBROUTINE !> \section arg_table_temp_calc_adjust_init Argument Table !! \htmlinclude arg_table_temp_calc_adjust_init.html