Skip to content

Commit f1e0f01

Browse files
committed
Params: Add do_not_log to param block open/close
This patch adds `do_not_log` to `openParameterBlock`, to prevent logging of `BLOCK%` `%BLOCK` entry and exit calls. The argument was not added to `closeParameterBlock`, since this state can be tracked inside the `block` with a new `log_access` field in `parameter_block`. This flag does not extend to parameters within the block, since (as far as I know) there is no way for a `get_param` to know if it is within a block or not. Even if it could know this, there would need to be some careful handling of nested blocks. The potential block/parameter inconsistency should be supported at some point, but for now it is the user's responsibility to consistently apply `do_not_log` to blocks and its contents.
1 parent 435ccaa commit f1e0f01

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/framework/MOM_file_parser.F90

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ module MOM_file_parser
5656
!> Specify the active parameter block
5757
type, private :: parameter_block ; private
5858
character(len=240) :: name = '' !< The active parameter block name
59+
logical :: log_access = .true.
60+
!< Log the entry and exit of the block (but not its contents)
5961
end type parameter_block
6062

6163
!> A structure that can be parsed to read and document run-time parameters.
@@ -2082,17 +2084,29 @@ subroutine clearParameterBlock(CS)
20822084
end subroutine clearParameterBlock
20832085

20842086
!> Tags blockName onto the end of the active parameter block name
2085-
subroutine openParameterBlock(CS,blockName,desc)
2087+
subroutine openParameterBlock(CS, blockName, desc, do_not_log)
20862088
type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
20872089
!! it is also a structure to parse for run-time parameters
20882090
character(len=*), intent(in) :: blockName !< The name of a parameter block being added
20892091
character(len=*), optional, intent(in) :: desc !< A description of the parameter block being added
2092+
logical, optional, intent(in) :: do_not_log
2093+
!< Log block entry if true. This only prevents logging of entry to the block, and not the contents.
20902094

20912095
type(parameter_block), pointer :: block => NULL()
2096+
logical :: do_log
2097+
2098+
do_log = .true.
2099+
if (present(do_not_log)) do_log = .not. do_not_log
2100+
20922101
if (associated(CS%blockName)) then
20932102
block => CS%blockName
20942103
block%name = pushBlockLevel(block%name,blockName)
2095-
call doc_openBlock(CS%doc,block%name,desc)
2104+
if (do_log) then
2105+
call doc_openBlock(CS%doc, block%name, desc)
2106+
block%log_access = .true.
2107+
else
2108+
block%log_access = .false.
2109+
endif
20962110
else
20972111
if (is_root_pe()) call MOM_error(FATAL, &
20982112
'openParameterBlock: A push was attempted before allocation.')
@@ -2111,7 +2125,7 @@ subroutine closeParameterBlock(CS)
21112125
if (is_root_pe().and.len_trim(block%name)==0) call MOM_error(FATAL, &
21122126
'closeParameterBlock: A pop was attempted on an empty stack. ("'//&
21132127
trim(block%name)//'")')
2114-
call doc_closeBlock(CS%doc,block%name)
2128+
if (block%log_access) call doc_closeBlock(CS%doc, block%name)
21152129
else
21162130
if (is_root_pe()) call MOM_error(FATAL, &
21172131
'closeParameterBlock: A pop was attempted before allocation.')

0 commit comments

Comments
 (0)