Skip to content

Commit

Permalink
+Make units argument mandatory for get_param_real
Browse files Browse the repository at this point in the history
  This commit includes changes to the get_param_real and log_param_real
interfaces to make the units arguments mandatory.  It also adds an optional
unscale argument to the log_param_real interfaces.  Without other changes in the
previous commits, it will cause the MOM6 code to fail to compile.  However, by
itself this commit does not change any answers or output.
  • Loading branch information
Hallberg-NOAA committed Jan 5, 2023
1 parent f86d762 commit 67c4d59
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/framework/MOM_file_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1411,69 +1411,79 @@ end subroutine log_param_int_array

!> Log the name and value of a real model parameter in documentation files.
subroutine log_param_real(CS, modulename, varname, value, desc, units, &
default, debuggingParam, like_default)
default, debuggingParam, like_default, unscale)
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) :: modulename !< The name of the calling module
character(len=*), intent(in) :: varname !< The name of the parameter to log
real, intent(in) :: value !< The value of the parameter to log
character(len=*), optional, intent(in) :: desc !< A description of this variable; if not
!! present, this parameter is not written to a doc file
character(len=*), optional, intent(in) :: units !< The units of this parameter
character(len=*), intent(in) :: units !< The units of this parameter
real, optional, intent(in) :: default !< The default value of the parameter
logical, optional, intent(in) :: debuggingParam !< If present and true, this parameter is
!! logged in the debugging parameter file
logical, optional, intent(in) :: like_default !< If present and true, log this parameter as
!! though it has the default value, even if there is no default.
real, optional, intent(in) :: unscale !< A reciprocal scaling factor that the parameter is
!! multiplied by before it is logged

real :: log_val ! The parameter value that is written out
character(len=240) :: mesg, myunits

log_val = value ; if (present(unscale)) log_val = unscale * value

write(mesg, '(" ",a," ",a,": ",a)') &
trim(modulename), trim(varname), trim(left_real(value))
trim(modulename), trim(varname), trim(left_real(log_val))
if (is_root_pe()) then
if (CS%log_open) write(CS%stdlog,'(a)') trim(mesg)
if (CS%log_to_stdout) write(CS%stdout,'(a)') trim(mesg)
endif

myunits="not defined"; if (present(units)) write(myunits(1:240),'(A)') trim(units)
write(myunits(1:240),'(A)') trim(units)
if (present(desc)) &
call doc_param(CS%doc, varname, desc, myunits, value, default, &
call doc_param(CS%doc, varname, desc, myunits, log_val, default, &
debuggingParam=debuggingParam, like_default=like_default)

end subroutine log_param_real

!> Log the name and values of an array of real model parameter in documentation files.
subroutine log_param_real_array(CS, modulename, varname, value, desc, &
units, default, debuggingParam, like_default)
units, default, debuggingParam, like_default, unscale)
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) :: modulename !< The name of the calling module
character(len=*), intent(in) :: varname !< The name of the parameter to log
real, dimension(:), intent(in) :: value !< The value of the parameter to log
character(len=*), optional, intent(in) :: desc !< A description of this variable; if not
!! present, this parameter is not written to a doc file
character(len=*), optional, intent(in) :: units !< The units of this parameter
character(len=*), intent(in) :: units !< The units of this parameter
real, optional, intent(in) :: default !< The default value of the parameter
logical, optional, intent(in) :: debuggingParam !< If present and true, this parameter is
!! logged in the debugging parameter file
logical, optional, intent(in) :: like_default !< If present and true, log this parameter as
!! though it has the default value, even if there is no default.
real, optional, intent(in) :: unscale !< A reciprocal scaling factor that the parameter is
!! multiplied by before it is logged

real, dimension(size(value)) :: log_val ! The array of parameter values that is written out
character(len=:), allocatable :: mesg
character(len=240) :: myunits

log_val(:) = value(:) ; if (present(unscale)) log_val(:) = unscale * value(:)

!write(mesg, '(" ",a," ",a,": ",ES19.12,99(",",ES19.12))') &
!write(mesg, '(" ",a," ",a,": ",G,99(",",G))') &
! trim(modulename), trim(varname), value
mesg = " " // trim(modulename) // " " // trim(varname) // ": " // trim(left_reals(value))
mesg = " " // trim(modulename) // " " // trim(varname) // ": " // trim(left_reals(log_val))
if (is_root_pe()) then
if (CS%log_open) write(CS%stdlog,'(a)') trim(mesg)
if (CS%log_to_stdout) write(CS%stdout,'(a)') trim(mesg)
endif

myunits="not defined"; if (present(units)) write(myunits(1:240),'(A)') trim(units)
write(myunits(1:240),'(A)') trim(units)
if (present(desc)) &
call doc_param(CS%doc, varname, desc, myunits, value, default, &
call doc_param(CS%doc, varname, desc, myunits, log_val, default, &
debuggingParam=debuggingParam, like_default=like_default)

end subroutine log_param_real_array
Expand Down Expand Up @@ -1772,7 +1782,7 @@ subroutine get_param_real(CS, modulename, varname, value, desc, units, &
!! read from the parameter file and logged
character(len=*), optional, intent(in) :: desc !< A description of this variable; if not
!! present, this parameter is not written to a doc file
character(len=*), optional, intent(in) :: units !< The units of this parameter
character(len=*), intent(in) :: units !< The units of this parameter
real, optional, intent(in) :: default !< The default value of the parameter
logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
!! if this variable is not found in the parameter file
Expand Down Expand Up @@ -1820,7 +1830,7 @@ subroutine get_param_real_array(CS, modulename, varname, value, desc, units, &
!! read from the parameter file and logged
character(len=*), optional, intent(in) :: desc !< A description of this variable; if not
!! present, this parameter is not written to a doc file
character(len=*), optional, intent(in) :: units !< The units of this parameter
character(len=*), intent(in) :: units !< The units of this parameter
real, optional, intent(in) :: default !< The default value of the parameter
logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
!! if this variable is not found in the parameter file
Expand Down

0 comments on commit 67c4d59

Please sign in to comment.