Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMS2: Replace time_interp_external IDs with a MOM-defined type #376

Merged
merged 4 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions config_src/drivers/FMS_cap/MOM_surface_forcing_gfdl.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module MOM_surface_forcing_gfdl
use MOM_grid, only : ocean_grid_type
use MOM_interpolate, only : init_external_field, time_interp_external
use MOM_interpolate, only : time_interp_external_init
use MOM_interpolate, only : external_field
use MOM_io, only : slasher, write_version_number, MOM_read_data
use MOM_io, only : read_netCDF_data
use MOM_io, only : stdout_if_root
Expand Down Expand Up @@ -153,8 +154,10 @@ module MOM_surface_forcing_gfdl
!! in inputdir/temp_restore_mask.nc and the field should
!! be named 'mask'
real, pointer, dimension(:,:) :: trestore_mask => NULL() !< Mask for SST restoring [nondim]
integer :: id_srestore = -1 !< An id number for time_interp_external.
integer :: id_trestore = -1 !< An id number for time_interp_external.
type(external_field) :: srestore_handle
!< Handle for time-interpolated salt restoration field
type(external_field) :: trestore_handle
!< Handle for time-interpolated temperature restoration field

type(forcing_diags), public :: handles !< Diagnostics handles

Expand Down Expand Up @@ -345,7 +348,7 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! Salinity restoring logic
if (CS%restore_salt) then
call time_interp_external(CS%id_srestore, Time, data_restore, scale=US%ppt_to_S)
call time_interp_external(CS%srestore_handle, Time, data_restore, scale=US%ppt_to_S)
! open_ocn_mask indicates where to restore salinity (1 means restore, 0 does not)
open_ocn_mask(:,:) = 1.0
if (CS%mask_srestore_under_ice) then ! Do not restore under sea-ice
Expand Down Expand Up @@ -403,7 +406,7 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! SST restoring logic
if (CS%restore_temp) then
call time_interp_external(CS%id_trestore, Time, data_restore, scale=US%degC_to_C)
call time_interp_external(CS%trestore_handle, Time, data_restore, scale=US%degC_to_C)
if ( CS%trestore_SPEAR_ECDA ) then
do j=js,je ; do i=is,ie
if (abs(data_restore(i,j)+1.8*US%degC_to_C) < 0.0001*US%degC_to_C) then
Expand Down Expand Up @@ -1610,7 +1613,7 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, wind_stagger)

if (CS%restore_salt) then
salt_file = trim(CS%inputdir) // trim(CS%salt_restore_file)
CS%id_srestore = init_external_field(salt_file, CS%salt_restore_var_name, MOM_domain=G%Domain)
CS%srestore_handle = init_external_field(salt_file, CS%salt_restore_var_name, MOM_domain=G%Domain)
call safe_alloc_ptr(CS%srestore_mask,isd,ied,jsd,jed); CS%srestore_mask(:,:) = 1.0
if (CS%mask_srestore) then ! read a 2-d file containing a mask for restoring fluxes
flnam = trim(CS%inputdir) // 'salt_restore_mask.nc'
Expand All @@ -1620,7 +1623,7 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, wind_stagger)

if (CS%restore_temp) then
temp_file = trim(CS%inputdir) // trim(CS%temp_restore_file)
CS%id_trestore = init_external_field(temp_file, CS%temp_restore_var_name, MOM_domain=G%Domain)
CS%trestore_handle = init_external_field(temp_file, CS%temp_restore_var_name, MOM_domain=G%Domain)
call safe_alloc_ptr(CS%trestore_mask,isd,ied,jsd,jed); CS%trestore_mask(:,:) = 1.0
if (CS%mask_trestore) then ! read a 2-d file containing a mask for restoring fluxes
flnam = trim(CS%inputdir) // 'temp_restore_mask.nc'
Expand Down
15 changes: 9 additions & 6 deletions config_src/drivers/mct_cap/mom_surface_forcing_mct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module MOM_surface_forcing_mct
use MOM_grid, only : ocean_grid_type
use MOM_interpolate, only : init_external_field, time_interp_external
use MOM_interpolate, only : time_interp_external_init
use MOM_interpolate, only : external_field
use MOM_io, only : slasher, write_version_number, MOM_read_data
use MOM_io, only : stdout
use MOM_restart, only : register_restart_field, restart_init, MOM_restart_CS
Expand Down Expand Up @@ -134,8 +135,10 @@ module MOM_surface_forcing_mct
!! in inputdir/temp_restore_mask.nc and the field should
!! be named 'mask'
real, pointer, dimension(:,:) :: trestore_mask => NULL() !< mask for SST restoring
integer :: id_srestore = -1 !< id number for time_interp_external.
integer :: id_trestore = -1 !< id number for time_interp_external.
type(external_field) :: srestore_handle
!< Handle for time-interpolated salt restoration field
type(external_field) :: trestore_handle
!< Handle for time-interpolated temperature restoration field

type(forcing_diags), public :: handles !< diagnostics handles
type(MOM_restart_CS), pointer :: restart_CSp => NULL() !< restart pointer
Expand Down Expand Up @@ -348,7 +351,7 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! Salinity restoring logic
if (restore_salinity) then
call time_interp_external(CS%id_srestore, Time, data_restore, scale=US%ppt_to_S)
call time_interp_external(CS%srestore_handle, Time, data_restore, scale=US%ppt_to_S)
! open_ocn_mask indicates where to restore salinity (1 means restore, 0 does not)
open_ocn_mask(:,:) = 1.0
if (CS%mask_srestore_under_ice) then ! Do not restore under sea-ice
Expand Down Expand Up @@ -405,7 +408,7 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! SST restoring logic
if (restore_sst) then
call time_interp_external(CS%id_trestore, Time, data_restore, scale=US%degC_to_C)
call time_interp_external(CS%trestore_handle, Time, data_restore, scale=US%degC_to_C)
do j=js,je ; do i=is,ie
delta_sst = data_restore(i,j) - sfc_state%SST(i,j)
delta_sst = sign(1.0,delta_sst)*min(abs(delta_sst),CS%max_delta_trestore)
Expand Down Expand Up @@ -1292,7 +1295,7 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, restore_salt,

if (present(restore_salt)) then ; if (restore_salt) then
salt_file = trim(CS%inputdir) // trim(CS%salt_restore_file)
CS%id_srestore = init_external_field(salt_file, CS%salt_restore_var_name, domain=G%Domain%mpp_domain)
CS%srestore_handle = init_external_field(salt_file, CS%salt_restore_var_name, domain=G%Domain%mpp_domain)
call safe_alloc_ptr(CS%srestore_mask,isd,ied,jsd,jed); CS%srestore_mask(:,:) = 1.0
if (CS%mask_srestore) then ! read a 2-d file containing a mask for restoring fluxes
flnam = trim(CS%inputdir) // 'salt_restore_mask.nc'
Expand All @@ -1302,7 +1305,7 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, restore_salt,

if (present(restore_temp)) then ; if (restore_temp) then
temp_file = trim(CS%inputdir) // trim(CS%temp_restore_file)
CS%id_trestore = init_external_field(temp_file, CS%temp_restore_var_name, domain=G%Domain%mpp_domain)
CS%trestore_handle = init_external_field(temp_file, CS%temp_restore_var_name, domain=G%Domain%mpp_domain)
call safe_alloc_ptr(CS%trestore_mask,isd,ied,jsd,jed); CS%trestore_mask(:,:) = 1.0
if (CS%mask_trestore) then ! read a 2-d file containing a mask for restoring fluxes
flnam = trim(CS%inputdir) // 'temp_restore_mask.nc'
Expand Down
28 changes: 17 additions & 11 deletions config_src/drivers/nuopc_cap/mom_surface_forcing_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module MOM_surface_forcing_nuopc
use MOM_grid, only : ocean_grid_type
use MOM_interpolate, only : init_external_field, time_interp_external
use MOM_interpolate, only : time_interp_external_init
use MOM_interpolate, only : external_field
use MOM_CFC_cap, only : CFC_cap_fluxes
use MOM_io, only : slasher, write_version_number, MOM_read_data
use MOM_io, only : stdout
Expand Down Expand Up @@ -146,10 +147,14 @@ module MOM_surface_forcing_nuopc
character(len=30) :: cfc11_var_name !< name of cfc11 in CFC_BC_file
character(len=30) :: cfc12_var_name !< name of cfc11 in CFC_BC_file
real, pointer, dimension(:,:) :: trestore_mask => NULL() !< mask for SST restoring
integer :: id_srestore = -1 !< id number for time_interp_external.
integer :: id_trestore = -1 !< id number for time_interp_external.
integer :: id_cfc11_atm = -1 !< id number for time_interp_external.
integer :: id_cfc12_atm = -1 !< id number for time_interp_external.
type(external_field) :: srestore_handle
!< Handle for time-interpolated salt restoration field
type(external_field) :: trestore_handle
!< Handle for time-interpolated temperature restoration field
type(external_field) :: cfc11_atm_handle
!< Handle for time-interpolated CFC11 restoration field
type(external_field) :: cfc12_atm_handle
!< Handle for time-interpolated CFC12 restoration field

! Diagnostics handles
type(forcing_diags), public :: handles
Expand Down Expand Up @@ -377,7 +382,7 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! Salinity restoring logic
if (restore_salinity) then
call time_interp_external(CS%id_srestore, Time, data_restore, scale=US%ppt_to_S)
call time_interp_external(CS%srestore_handle, Time, data_restore, scale=US%ppt_to_S)
! open_ocn_mask indicates where to restore salinity (1 means restore, 0 does not)
open_ocn_mask(:,:) = 1.0
if (CS%mask_srestore_under_ice) then ! Do not restore under sea-ice
Expand Down Expand Up @@ -434,7 +439,7 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! SST restoring logic
if (restore_sst) then
call time_interp_external(CS%id_trestore, Time, data_restore, scale=US%degC_to_C)
call time_interp_external(CS%trestore_handle, Time, data_restore, scale=US%degC_to_C)
do j=js,je ; do i=is,ie
delta_sst = data_restore(i,j) - sfc_state%SST(i,j)
delta_sst = sign(1.0,delta_sst)*min(abs(delta_sst),CS%max_delta_trestore)
Expand Down Expand Up @@ -596,7 +601,8 @@ subroutine convert_IOB_to_fluxes(IOB, fluxes, index_bounds, Time, valid_time, G,

! CFCs
if (CS%use_CFC) then
call CFC_cap_fluxes(fluxes, sfc_state, G, US, CS%Rho0, Time, CS%id_cfc11_atm, CS%id_cfc11_atm)
call CFC_cap_fluxes(fluxes, sfc_state, G, US, CS%Rho0, Time, &
CS%cfc11_atm_handle, CS%cfc11_atm_handle)
endif

if (associated(IOB%salt_flux)) then
Expand Down Expand Up @@ -1394,7 +1400,7 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, restore_salt,

if (present(restore_salt)) then ; if (restore_salt) then
salt_file = trim(CS%inputdir) // trim(CS%salt_restore_file)
CS%id_srestore = init_external_field(salt_file, CS%salt_restore_var_name, domain=G%Domain%mpp_domain)
CS%srestore_handle = init_external_field(salt_file, CS%salt_restore_var_name, domain=G%Domain%mpp_domain)
call safe_alloc_ptr(CS%srestore_mask,isd,ied,jsd,jed); CS%srestore_mask(:,:) = 1.0
if (CS%mask_srestore) then ! read a 2-d file containing a mask for restoring fluxes
flnam = trim(CS%inputdir) // 'salt_restore_mask.nc'
Expand All @@ -1404,7 +1410,7 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, restore_salt,

if (present(restore_temp)) then ; if (restore_temp) then
temp_file = trim(CS%inputdir) // trim(CS%temp_restore_file)
CS%id_trestore = init_external_field(temp_file, CS%temp_restore_var_name, domain=G%Domain%mpp_domain)
CS%trestore_handle = init_external_field(temp_file, CS%temp_restore_var_name, domain=G%Domain%mpp_domain)
call safe_alloc_ptr(CS%trestore_mask,isd,ied,jsd,jed); CS%trestore_mask(:,:) = 1.0
if (CS%mask_trestore) then ! read a 2-d file containing a mask for restoring fluxes
flnam = trim(CS%inputdir) // 'temp_restore_mask.nc'
Expand All @@ -1430,8 +1436,8 @@ subroutine surface_forcing_init(Time, G, US, param_file, diag, CS, restore_salt,
"The name of the variable representing CFC-12 in "//&
"CFC_BC_FILE.", default="CFC_12", do_not_log=.true.)

CS%id_cfc11_atm = init_external_field(CS%CFC_BC_file, CS%cfc11_var_name, domain=G%Domain%mpp_domain)
CS%id_cfc12_atm = init_external_field(CS%CFC_BC_file, CS%cfc12_var_name, domain=G%Domain%mpp_domain)
CS%cfc11_atm_handle = init_external_field(CS%CFC_BC_file, CS%cfc11_var_name, domain=G%Domain%mpp_domain)
CS%cfc12_atm_handle = init_external_field(CS%CFC_BC_file, CS%cfc12_var_name, domain=G%Domain%mpp_domain)
endif
endif

Expand Down
Loading