Skip to content

Commit d8da512

Browse files
committed
+Add the optional argument old_name to get_param
Added the new optional argument old_name to the 8 get_param() routines. This new capability allows for an archaic parameter name to be specified and for appropriate warnings encouraging the user to migrate to using the new name while still setting the parameter as intended, or error messages in the case of inconsistent setting via the archaic name and the correct name. The logging inside of the MOM_parameter_doc files only uses the correct parameter name. Also added the new optional argument set to the 8 read_param routines, to indicate whether a parameter has been found and successfully set. The new set argument is now being used in read_param() calls in obsolete_int(), obsolete_real(), obsolete_char() and obsolete_logical(). Obsolete_logical() in particular was substantially simplified by the use of this new argument, and is now only about half as long as it was. The read_param() set argument is also used in all of the get_param() routines when they are given an old_name argument. The new old_name argument to get_param() is not yet being used in the version of the MOM6 code that is being checked in, but it has been tested extensively by adding or modifying get_param calls in a variant of the initialization code, and it will be used in an updated version of github.com//pull/725 to gracefully handle the deprecation of 4 parameter names. All answers are bitwise identical, but there are new optional arguments to two widely used interfaces.
1 parent dd1f3f5 commit d8da512

File tree

2 files changed

+274
-51
lines changed

2 files changed

+274
-51
lines changed

src/diagnostics/MOM_obsolete_params.F90

+13-24
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,15 @@ subroutine obsolete_logical(param_file, varname, warning_val, hint)
168168
character(len=*), optional, intent(in) :: hint !< A hint to the user about what to do.
169169
! Local variables
170170
logical :: test_logic, fatal_err
171+
logical :: var_is_set ! True if this value was read by read_param.
171172
character(len=128) :: hint_msg
172173

173-
test_logic = .false. ; call read_param(param_file, varname, test_logic)
174+
test_logic = .false. ; call read_param(param_file, varname, test_logic, set=var_is_set)
174175
fatal_err = .true.
175-
if (present(warning_val)) fatal_err = (warning_val .neqv. .true.)
176+
if (var_is_set .and. present(warning_val)) fatal_err = (warning_val .neqv. test_logic)
176177
hint_msg = " " ; if (present(hint)) hint_msg = hint
177178

178-
if (test_logic) then
179-
if (fatal_err) then
180-
call MOM_ERROR(FATAL, "MOM_obsolete_params: "//trim(varname)// &
181-
" is an obsolete run-time flag, and should not be used. "// &
182-
trim(hint_msg))
183-
else
184-
call MOM_ERROR(WARNING, "MOM_obsolete_params: "//trim(varname)// &
185-
" is an obsolete run-time flag. "//trim(hint_msg))
186-
endif
187-
endif
188-
189-
test_logic = .true. ; call read_param(param_file, varname, test_logic)
190-
fatal_err = .true.
191-
if (present(warning_val)) fatal_err = (warning_val .neqv. .false.)
192-
193-
if (.not.test_logic) then
179+
if (var_is_set) then
194180
if (fatal_err) then
195181
call MOM_ERROR(FATAL, "MOM_obsolete_params: "//trim(varname)// &
196182
" is an obsolete run-time flag, and should not be used. "// &
@@ -211,12 +197,13 @@ subroutine obsolete_char(param_file, varname, warning_val, hint)
211197
character(len=*), optional, intent(in) :: hint !< A hint to the user about what to do.
212198
! Local variables
213199
character(len=200) :: test_string, hint_msg
200+
logical :: var_is_set ! True if this value was read by read_param.
214201
logical :: only_warn
215202

216-
test_string = ''; call read_param(param_file, varname, test_string)
203+
test_string = ''; call read_param(param_file, varname, test_string, set=var_is_set)
217204
hint_msg = " " ; if (present(hint)) hint_msg = hint
218205

219-
if (len_trim(test_string) > 0) then
206+
if (var_is_set) then
220207
only_warn = .false.
221208
if (present(warning_val)) then ! Check if test_string and warning_val are the same.
222209
if (len_trim(warning_val) == len_trim(test_string)) then
@@ -246,15 +233,16 @@ subroutine obsolete_real(param_file, varname, warning_val, hint, only_warn)
246233

247234
! Local variables
248235
real :: test_val, warn_val
236+
logical :: var_is_set ! True if this value was read by read_param.
249237
logical :: issue_warning
250238
character(len=128) :: hint_msg
251239

252-
test_val = -9e35; call read_param(param_file, varname, test_val)
240+
test_val = -9e35; call read_param(param_file, varname, test_val, set=var_is_set)
253241
warn_val = -9e35; if (present(warning_val)) warn_val = warning_val
254242
hint_msg = " " ; if (present(hint)) hint_msg = hint
255243
issue_warning = .false. ; if (present(only_warn)) issue_warning = only_warn
256244

257-
if (test_val /= -9e35) then
245+
if (var_is_set) then
258246
if ((test_val == warn_val) .or. issue_warning) then
259247
call MOM_ERROR(WARNING, "MOM_obsolete_params: "//trim(varname)// &
260248
" is an obsolete run-time flag. "//trim(hint_msg))
@@ -273,14 +261,15 @@ subroutine obsolete_int(param_file, varname, warning_val, hint)
273261
integer, optional, intent(in) :: warning_val !< An allowed value that causes a warning instead of an error.
274262
character(len=*), optional, intent(in) :: hint !< A hint to the user about what to do.
275263
! Local variables
264+
logical :: var_is_set ! True if this value was read by read_param.
276265
integer :: test_val, warn_val
277266
character(len=128) :: hint_msg
278267

279-
test_val = -123456788; call read_param(param_file, varname, test_val)
268+
test_val = -123456788; call read_param(param_file, varname, test_val, set=var_is_set)
280269
warn_val = -123456788; if (present(warning_val)) warn_val = warning_val
281270
hint_msg = " " ; if (present(hint)) hint_msg = hint
282271

283-
if (test_val /= -123456788) then
272+
if (var_is_set) then
284273
if (test_val == warn_val) then
285274
call MOM_ERROR(WARNING, "MOM_obsolete_params: "//trim(varname)// &
286275
" is an obsolete run-time flag. "//trim(hint_msg))

0 commit comments

Comments
 (0)