Skip to content

Commit

Permalink
Params: Add do_not_log to param block open/close
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marshallward committed Jan 31, 2024
1 parent 435ccaa commit f1e0f01
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/framework/MOM_file_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ module MOM_file_parser
!> Specify the active parameter block
type, private :: parameter_block ; private
character(len=240) :: name = '' !< The active parameter block name
logical :: log_access = .true.
!< Log the entry and exit of the block (but not its contents)
end type parameter_block

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

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

type(parameter_block), pointer :: block => NULL()
logical :: do_log

do_log = .true.
if (present(do_not_log)) do_log = .not. do_not_log

if (associated(CS%blockName)) then
block => CS%blockName
block%name = pushBlockLevel(block%name,blockName)
call doc_openBlock(CS%doc,block%name,desc)
if (do_log) then
call doc_openBlock(CS%doc, block%name, desc)
block%log_access = .true.
else
block%log_access = .false.
endif
else
if (is_root_pe()) call MOM_error(FATAL, &
'openParameterBlock: A push was attempted before allocation.')
Expand All @@ -2111,7 +2125,7 @@ subroutine closeParameterBlock(CS)
if (is_root_pe().and.len_trim(block%name)==0) call MOM_error(FATAL, &
'closeParameterBlock: A pop was attempted on an empty stack. ("'//&
trim(block%name)//'")')
call doc_closeBlock(CS%doc,block%name)
if (block%log_access) call doc_closeBlock(CS%doc, block%name)
else
if (is_root_pe()) call MOM_error(FATAL, &
'closeParameterBlock: A pop was attempted before allocation.')
Expand Down

0 comments on commit f1e0f01

Please sign in to comment.