Skip to content

Commit

Permalink
Merge pull request mom-ocean#908 from jkrasting/user/jpk/trap-kd-turb
Browse files Browse the repository at this point in the history
Feature to flag and trap cases where obsolete restart fields are attempted to be used
  • Loading branch information
Hallberg-NOAA authored Apr 12, 2019
2 parents d821a67 + 2c89df5 commit 317f91b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/framework/MOM_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module MOM_restart
public restart_init, restart_end, restore_state, register_restart_field
public save_restart, query_initialized, restart_init_end, vardesc
public restart_files_exist, determine_is_new_run, is_new_run
public register_restart_field_as_obsolete

!> A type for making arrays of pointers to 4-d arrays
type p4d
Expand Down Expand Up @@ -61,11 +62,18 @@ module MOM_restart
character(len=32) :: var_name !< A name by which a variable may be queried.
end type field_restart

!> A structure to store information about restart fields that are no longer used
type obsolete_restart
character(len=32) :: field_name !< Name of restart field that is no longer in use
character(len=32) :: replacement_name !< Name of replacement restart field, if applicable
end type obsolete_restart

!> A restart registry and the control structure for restarts
type, public :: MOM_restart_CS ; private
logical :: restart !< restart is set to .true. if the run has been started from a full restart
!! file. Otherwise some fields must be initialized approximately.
integer :: novars = 0 !< The number of restart fields that have been registered.
integer :: num_obsolete_vars = 0 !< The number of obsolete restart fields that have been registered.
logical :: parallel_restartfiles !< If true, each PE writes its own restart file,
!! otherwise they are combined internally.
logical :: large_file_support !< If true, NetCDF 3.6 or later is being used
Expand All @@ -82,6 +90,9 @@ module MOM_restart
!> An array of descriptions of the registered fields
type(field_restart), pointer :: restart_field(:) => NULL()

!> An array of obsolete restart fields
type(obsolete_restart), pointer :: restart_obsolete(:) => NULL()

!>@{ Pointers to the fields that have been registered for restarts
type(p0d), pointer :: var_ptr0d(:) => NULL()
type(p1d), pointer :: var_ptr1d(:) => NULL()
Expand Down Expand Up @@ -112,6 +123,16 @@ module MOM_restart
end interface

contains
!!> Register a restart field as obsolete
subroutine register_restart_field_as_obsolete(field_name, replacement_name, CS)
character(*), intent(in) :: field_name !< Name of restart field that is no longer in use
character(*), intent(in) :: replacement_name !< Name of replacement restart field, if applicable
type(MOM_restart_CS), pointer :: CS !< A pointer to a MOM_restart_CS object (intent in/out)

CS%num_obsolete_vars = CS%num_obsolete_vars+1
CS%restart_obsolete(CS%num_obsolete_vars)%field_name = field_name
CS%restart_obsolete(CS%num_obsolete_vars)%replacement_name = replacement_name
end subroutine register_restart_field_as_obsolete

!> Register a 3-d field for restarts, providing the metadata in a structure
subroutine register_restart_field_ptr3d(f_ptr, var_desc, mandatory, CS)
Expand Down Expand Up @@ -1062,6 +1083,17 @@ subroutine restore_state(filename, directory, day, G, CS)
allocate(fields(nvar))
call get_file_fields(unit(n),fields(1:nvar))

do m=1, nvar
call get_file_atts(fields(m),name=varname)
do i=1,CS%num_obsolete_vars
if (adjustl(lowercase(trim(varname))) == adjustl(lowercase(trim(CS%restart_obsolete(i)%field_name)))) then
call MOM_error(FATAL, "MOM_restart restore_state: Attempting to use obsolete restart field "//&
trim(varname)//" - the new corresponding restart field is "//&
trim(CS%restart_obsolete(i)%replacement_name))
endif
enddo
enddo

missing_fields = 0

do m=1,CS%novars
Expand Down Expand Up @@ -1433,6 +1465,7 @@ subroutine restart_init(param_file, CS, restart_root)
default=.true.)

allocate(CS%restart_field(CS%max_fields))
allocate(CS%restart_obsolete(CS%max_fields))
allocate(CS%var_ptr0d(CS%max_fields))
allocate(CS%var_ptr1d(CS%max_fields))
allocate(CS%var_ptr2d(CS%max_fields))
Expand All @@ -1456,6 +1489,7 @@ subroutine restart_end(CS)
type(MOM_restart_CS), pointer :: CS !< A pointer to a MOM_restart_CS object

if (associated(CS%restart_field)) deallocate(CS%restart_field)
if (associated(CS%restart_obsolete)) deallocate(CS%restart_obsolete)
if (associated(CS%var_ptr0d)) deallocate(CS%var_ptr0d)
if (associated(CS%var_ptr1d)) deallocate(CS%var_ptr1d)
if (associated(CS%var_ptr2d)) deallocate(CS%var_ptr2d)
Expand Down
4 changes: 4 additions & 0 deletions src/parameterizations/vertical/MOM_set_viscosity.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module MOM_set_visc
use MOM_cvmix_conv, only : cvmix_conv_is_used
use MOM_CVMix_ddiff, only : CVMix_ddiff_is_used
use MOM_restart, only : register_restart_field, query_initialized, MOM_restart_CS
use MOM_restart, only : register_restart_field_as_obsolete
use MOM_safe_alloc, only : safe_alloc_ptr, safe_alloc_alloc
use MOM_unit_scaling, only : unit_scale_type
use MOM_variables, only : thermo_var_ptrs, vertvisc_type
Expand Down Expand Up @@ -2025,6 +2026,9 @@ subroutine set_visc_init(Time, G, GV, US, param_file, diag, visc, CS, restart_CS
diag%axesCv1, Time, 'Number of layers in viscous mixed layer at v points', 'm')
endif

call register_restart_field_as_obsolete('Kd_turb','Kd_shear', restart_CS)
call register_restart_field_as_obsolete('Kv_turb','Kv_shear', restart_CS)

if ((US%m_to_Z_restart /= 0.0) .and. (US%m_to_Z_restart /= US%m_to_Z)) then
Z_rescale = US%m_to_Z / US%m_to_Z_restart
if (associated(visc%Kd_shear)) then ; if (query_initialized(visc%Kd_shear, "Kd_shear", restart_CS)) then
Expand Down

0 comments on commit 317f91b

Please sign in to comment.