From 18211b0c1fa19b73de6207f703beec719d945a4d Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 19 May 2026 13:12:24 +1000 Subject: [PATCH 01/14] generalise rofi spreading to arbtitrary components, and add into post atm --- mediator/med_phases_post_atm_mod.F90 | 33 +++++++ mediator/med_phases_post_rof_mod.F90 | 130 ++++++++++++--------------- 2 files changed, 92 insertions(+), 71 deletions(-) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index c275c0ebf..cb53f705e 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -12,6 +12,9 @@ module med_phases_post_atm_mod character(*), parameter :: u_FILE_u = & __FILE__ + logical :: first_time = .true. + character(len=9), parameter :: fields_to_spread_runoff(1) = & + ['Foxx_rofi'] !----------------------------------------------------------------------------- contains @@ -35,6 +38,8 @@ subroutine med_phases_post_atm(gcomp, rc) use med_utils_mod , only : chkerr => med_utils_ChkErr use med_internalstate_mod , only : compocn, compatm, compice, complnd, compwav, coupling_mode use perf_mod , only : t_startf, t_stopf + use shr_log_mod , only : shr_log_error + use med_phases_post_rof_mod, only: med_phases_post_rof_init_rof_spread_rofi, med_phases_post_rof_spread_rofi ! input/output variables type(ESMF_GridComp) :: gcomp @@ -44,6 +49,8 @@ subroutine med_phases_post_atm(gcomp, rc) type(InternalState) :: is_local type(ESMF_Clock) :: dClock character(len=*), parameter :: subname='(med_phases_post_atm)' + character(len=CL) :: atm2ocn_ice_spread + logical :: isPresent, isSet !------------------------------------------------------------------------------- rc = ESMF_SUCCESS @@ -125,6 +132,32 @@ subroutine med_phases_post_atm(gcomp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if + call NUOPC_CompAttributeGet(gcomp, name='atm2ocn_ice_spread', value=atm2ocn_ice_spread, isPresent=isPresent, isSet=isSet, rc=rc) + + if (isPresent .and. isSet) then + + if (first_time) then + call med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, atm2ocn_ice_spread, compocn, rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + first_time=.false. + end if + + do n = 1, size(fields_to_spread_runoff) + call ESMF_FieldBundleGet(is_local%wrap%FBImp(compatm,compocn), fieldName=trim(fields_to_spread_runoff(n)), isPresent=exists, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) then + call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) + return + end if + if (exists) then + call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), is_local%wrap%FBImp(compatm,compocn), compocn, rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + else + call shr_log_error(string=trim(subname)//" Runoff field to spread: "//trim(fields_to_spread_runoff(n))//" does not exist", line=__LINE__,file=u_FILE_u, rc=rc) + return + end if + end do + end if + if (dbug_flag > 20) then call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO) end if diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 7eff535de..00350d9bc 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -32,7 +32,7 @@ module med_phases_post_rof_mod implicit none private - public :: med_phases_post_rof_init + public :: med_phases_post_rof_init, med_phases_post_rof_init_rof_spread_rofi, med_phases_post_rof_spread_rofi public :: med_phases_post_rof private :: med_phases_post_rof_create_rof_field_bundle private :: med_phases_post_rof_remove_negative_runoff @@ -49,6 +49,7 @@ module med_phases_post_rof_mod logical :: remove_negative_runoff_lnd logical :: remove_negative_runoff_glc logical :: spread_rofi_nh, spread_rofi_sh + logical :: first_time = .true. character(len=CL) :: rof2ocn_ice_spread character(len=9), parameter :: fields_to_remove_negative_runoff_lnd(2) = & @@ -144,7 +145,6 @@ subroutine med_phases_post_rof(gcomp, rc) real(r8), pointer :: data_copy(:) integer :: n logical :: exists - logical :: first_time = .true. character(len=*), parameter :: subname='(med_phases_post_rof)' !--------------------------------------- @@ -157,7 +157,7 @@ subroutine med_phases_post_rof(gcomp, rc) ! unclear why this can't be in med_phases_post_rof_init, possibly pio not initialised if ((spread_rofi_nh .or. spread_rofi_sh) .and. first_time) then - call med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) + call med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, rof2ocn_ice_spread, comprof, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return first_time=.false. endif @@ -203,7 +203,7 @@ subroutine med_phases_post_rof(gcomp, rc) return end if if (exists) then - call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), rc) + call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), FBrof_r, comprof, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return else call shr_log_error(string=trim(subname)//" Runoff field to spread: "//trim(fields_to_spread_runoff(n))//" does not exist", line=__LINE__,file=u_FILE_u, rc=rc) @@ -459,13 +459,16 @@ subroutine med_phases_post_rof_remove_negative_runoff(gcomp, field_name, rc) end subroutine med_phases_post_rof_remove_negative_runoff - subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) + subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, rof2ocn_ice_spread, comp, rc) !--------------------------------------------------------------- use med_io_mod , only : med_io_read use shr_reprosum_mod , only : shr_reprosum_calc ! input/output variables type(ESMF_GridComp) :: gcomp + character(len=*), intent(in) :: fields_to_spread_runoff(:) + character(len=CL) :: rof2ocn_ice_spread + integer, intent(in) :: comp integer, intent(out) :: rc @@ -478,13 +481,12 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) real(r8), allocatable:: rof2ocn_a_weight(:,:) real(r8) :: global_sum(2) ! Antarctic, Greenland (frozen) runoff integer :: n, i, month, comm + logical :: error = .false. integer, parameter :: dbug_threshold = 0 ! threshold for writing debug information in this subroutine character(len=*), parameter :: subname='(med_phases_post_rof_mod: med_phases_post_rof_init_rof_spread_rofi)' !--------------------------------------- - ! to do - make component configurable (could be comprof or compatm) - rc = ESMF_SUCCESS call t_startf('MED:'//subname) @@ -508,7 +510,7 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) ! Create module fields on rof mesh ! ------------------------------- - call fldbun_getmesh(is_local%wrap%FBImp(comprof,comprof), mesh_l, rc) + call fldbun_getmesh(is_local%wrap%FBImp(comp,comp), mesh_l, rc) if (chkerr(rc,__LINE__,u_FILE_u)) return FBrof_pattern = ESMF_FieldBundleCreate(name='FBrof_pattern', rc=rc) @@ -533,8 +535,8 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) call med_io_read(rof2ocn_ice_spread, vm, FBrof_pattern, pre='pattern', ungridded_nc=.true., rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return - areas => is_local%wrap%mesh_info(comprof)%areas - lats => is_local%wrap%mesh_info(comprof)%lats + areas => is_local%wrap%mesh_info(comp)%areas + lats => is_local%wrap%mesh_info(comp)%lats allocate(rof2ocn_a_weight(size(areas),2)) @@ -566,33 +568,29 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) if (global_sum(1) < (100.0_r8 * tiny(1.0_r8))) then if (maintask) write(logunit,*) trim(subname)//": In rof2ocn_spread file, "//& "Southern hemisphere sum is zero, or negative. Month = ",month, 'global_sum = ',global_sum(1) - spread_rofi_sh = .false. + error = .true. endif if (global_sum(2) < (100.0_r8 * tiny(1.0_r8))) then if (maintask) write(logunit,*) trim(subname)//": In rof2ocn_spread file, "//& "Northern hemisphere sum is zero, or negative. Month = ",month, 'global_sum = ',global_sum(2) - spread_rofi_nh = .false. + error = .true. endif ! adjust correction so that it's sums to 1 in each hemisphere - if (spread_rofi_sh) then - do i = 1, size(areas) - if (lats(i) < 0.0_r8) then - rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(1) - end if - end do - end if - if (spread_rofi_nh) then - do i = 1, size(areas) - if (lats(i) >= 0.0_r8) then - rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(2) - end if - end do - end if + do i = 1, size(areas) + if (lats(i) < 0.0_r8) then + rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(1) + end if + end do + do i = 1, size(areas) + if (lats(i) >= 0.0_r8) then + rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(2) + end if + end do enddo ! month - if ( .not. (spread_rofi_nh .or. spread_rofi_sh)) then + if (error) then call shr_log_error(string=trim(subname)//": error in rof2ocn_spread file, "//& "sum in each hemispheres is zero, or negative", line=__LINE__,file=u_FILE_u, rc=rc) return @@ -607,7 +605,7 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, rc) end subroutine med_phases_post_rof_init_rof_spread_rofi - subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, rc) + subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, field_bundle, comp, rc) !--------------------------------------------------------------- ! For one runoff field, spread runoff according to the pattern prescribed in spread_rofi_weights. use shr_reprosum_mod , only : shr_reprosum_calc @@ -615,6 +613,8 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, rc) ! input/output variables type(ESMF_GridComp) :: gcomp character(len=*), intent(in) :: field_name ! name of runoff flux field to process + type(ESMF_FieldBundle) :: field_bundle + integer, intent(in) :: comp integer, intent(out) :: rc ! local variables @@ -652,29 +652,25 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, rc) call ESMF_GridCompGetInternalState(gcomp, is_local, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - areas => is_local%wrap%mesh_info(comprof)%areas - lats => is_local%wrap%mesh_info(comprof)%lats + areas => is_local%wrap%mesh_info(comp)%areas + lats => is_local%wrap%mesh_info(comp)%lats - call fldbun_getdata1d(FBrof_r, trim(field_name), runoff_flux, rc=rc) + call fldbun_getdata1d(field_bundle, trim(field_name), runoff_flux, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return allocate(rof2ocn_a_weight(size(runoff_flux),2)) rof2ocn_a_weight = 0.0_r8 - if (spread_rofi_sh) then - do n = 1, size(runoff_flux) - if (lats(n) < 0.0_r8) then - rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) - end if - end do - end if - if (spread_rofi_nh) then - do n = 1, size(runoff_flux) - if (lats(n) >= 0.0_r8) then - rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) - end if - end do - end if + do n = 1, size(runoff_flux) + if (lats(n) < 0.0_r8) then + rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) + end if + end do + do n = 1, size(runoff_flux) + if (lats(n) >= 0.0_r8) then + rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) + end if + end do ! Get the MPI communicator from the VM call ESMF_GridCompGet(gcomp, vm=vm, rc=rc) @@ -697,41 +693,33 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return ! spread runoff by the saved pattern for the model month - if (spread_rofi_sh) then + do n = 1, size(runoff_flux) + if (lats(n) < 0.0_r8) then + runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(1) + end if + end do + + do n = 1, size(runoff_flux) + if (lats(n) >= 0.0_r8) then + runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(2) + end if + end do + + if (dbug_flag > dbug_threshold) then + + ! calculate the new global sum (after correction), difference should be equal to 0 + rof2ocn_a_weight = 0.0_r8 do n = 1, size(runoff_flux) if (lats(n) < 0.0_r8) then - runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(1) + rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) end if end do - end if - if (spread_rofi_nh) then do n = 1, size(runoff_flux) if (lats(n) >= 0.0_r8) then - runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(2) + rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) end if end do - end if - - if (dbug_flag > dbug_threshold) then - - ! calculate the new global sum (after correction), difference should be equal to 0 - rof2ocn_a_weight = 0.0_r8 - if (spread_rofi_sh) then - do n = 1, size(runoff_flux) - if (lats(n) < 0.0_r8) then - rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) - end if - end do - end if - - if (spread_rofi_nh) then - do n = 1, size(runoff_flux) - if (lats(n) >= 0.0_r8) then - rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) - end if - end do - end if call shr_reprosum_calc(rof2ocn_a_weight, global_sum, size(runoff_flux), size(runoff_flux), 2, & commid=comm) From 17dd52b57c8abc90d1ab05cdbfae7b6ff1d4b197 Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 19 May 2026 13:28:21 +1000 Subject: [PATCH 02/14] add missing variable declarations and imports --- mediator/med_phases_post_atm_mod.F90 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index cb53f705e..ae5f6dcf4 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -27,6 +27,7 @@ subroutine med_phases_post_atm(gcomp, rc) !--------------------------------------- use NUOPC_Mediator , only : NUOPC_MediatorGet + use NUOPC , only : NUOPC_CompAttributeGet use ESMF , only : ESMF_Clock, ESMF_ClockIsCreated use ESMF , only : ESMF_GridComp, ESMF_GridCompGet, ESMF_FieldBundleGet use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_SUCCESS @@ -51,6 +52,7 @@ subroutine med_phases_post_atm(gcomp, rc) character(len=*), parameter :: subname='(med_phases_post_atm)' character(len=CL) :: atm2ocn_ice_spread logical :: isPresent, isSet + integer :: n !------------------------------------------------------------------------------- rc = ESMF_SUCCESS @@ -143,12 +145,12 @@ subroutine med_phases_post_atm(gcomp, rc) end if do n = 1, size(fields_to_spread_runoff) - call ESMF_FieldBundleGet(is_local%wrap%FBImp(compatm,compocn), fieldName=trim(fields_to_spread_runoff(n)), isPresent=exists, rc=rc) + call ESMF_FieldBundleGet(is_local%wrap%FBImp(compatm,compocn), fieldName=trim(fields_to_spread_runoff(n)), isPresent=isPresent, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) then call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) return end if - if (exists) then + if (isPresent) then call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), is_local%wrap%FBImp(compatm,compocn), compocn, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return else From 51a70845c0ec9fec943804370d1863e456608fcd Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Mon, 25 May 2026 15:33:21 +1000 Subject: [PATCH 03/14] update rofi field spreading name --- mediator/med_phases_post_atm_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index ae5f6dcf4..4e9ffe625 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -14,7 +14,7 @@ module med_phases_post_atm_mod __FILE__ logical :: first_time = .true. character(len=9), parameter :: fields_to_spread_runoff(1) = & - ['Foxx_rofi'] + ['Faoa_rofi'] !----------------------------------------------------------------------------- contains From 1b264ebb3e4629498c1f94be01b9bcf95f9e2b5c Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 16 Jun 2026 15:23:19 +1000 Subject: [PATCH 04/14] share more code between post rof and post atm, add in `spread_rofi_*h` checks --- mediator/med_phases_post_atm_mod.F90 | 29 +--- mediator/med_phases_post_rof_mod.F90 | 202 ++++++++++++++++----------- 2 files changed, 122 insertions(+), 109 deletions(-) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index 4e9ffe625..d452859ef 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -40,7 +40,7 @@ subroutine med_phases_post_atm(gcomp, rc) use med_internalstate_mod , only : compocn, compatm, compice, complnd, compwav, coupling_mode use perf_mod , only : t_startf, t_stopf use shr_log_mod , only : shr_log_error - use med_phases_post_rof_mod, only: med_phases_post_rof_init_rof_spread_rofi, med_phases_post_rof_spread_rofi + use med_phases_post_rof_mod, only: med_phases_post_rof_spread_rofi_field_bundle ! input/output variables type(ESMF_GridComp) :: gcomp @@ -134,30 +134,9 @@ subroutine med_phases_post_atm(gcomp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if - call NUOPC_CompAttributeGet(gcomp, name='atm2ocn_ice_spread', value=atm2ocn_ice_spread, isPresent=isPresent, isSet=isSet, rc=rc) - - if (isPresent .and. isSet) then - - if (first_time) then - call med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, atm2ocn_ice_spread, compocn, rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - first_time=.false. - end if - - do n = 1, size(fields_to_spread_runoff) - call ESMF_FieldBundleGet(is_local%wrap%FBImp(compatm,compocn), fieldName=trim(fields_to_spread_runoff(n)), isPresent=isPresent, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) then - call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) - return - end if - if (isPresent) then - call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), is_local%wrap%FBImp(compatm,compocn), compocn, rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - else - call shr_log_error(string=trim(subname)//" Runoff field to spread: "//trim(fields_to_spread_runoff(n))//" does not exist", line=__LINE__,file=u_FILE_u, rc=rc) - return - end if - end do + if (trim(coupling_mode) == 'access-esm') then + call med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_runoff, is_local%wrap%FBImp(compatm,compocn), compocn, rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return end if if (dbug_flag > 20) then diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 00350d9bc..b6520dc72 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -32,7 +32,7 @@ module med_phases_post_rof_mod implicit none private - public :: med_phases_post_rof_init, med_phases_post_rof_init_rof_spread_rofi, med_phases_post_rof_spread_rofi + public :: med_phases_post_rof_init, med_phases_post_rof_spread_rofi_field_bundle public :: med_phases_post_rof private :: med_phases_post_rof_create_rof_field_bundle private :: med_phases_post_rof_remove_negative_runoff @@ -49,8 +49,7 @@ module med_phases_post_rof_mod logical :: remove_negative_runoff_lnd logical :: remove_negative_runoff_glc logical :: spread_rofi_nh, spread_rofi_sh - logical :: first_time = .true. - character(len=CL) :: rof2ocn_ice_spread + logical :: spreading_initialized = .false. character(len=9), parameter :: fields_to_remove_negative_runoff_lnd(2) = & ['Forr_rofl', & @@ -108,21 +107,9 @@ subroutine med_phases_post_rof_init(gcomp, rc) remove_negative_runoff_glc = .false. end if - call NUOPC_CompAttributeGet(gcomp, name='rof2ocn_ice_spread', value=rof2ocn_ice_spread, isPresent=isPresent, isSet=isSet, rc=rc) - if (chkerr(rc,__LINE__,u_FILE_u)) return - if (isPresent .and. isSet) then - spread_rofi_nh = .true. - spread_rofi_sh = .true. - else - spread_rofi_nh = .false. - spread_rofi_sh = .false. - end if - if (maintask) then write(logunit,'(a,l7)') trim(subname)//' remove_negative_runoff_lnd = ', remove_negative_runoff_lnd write(logunit,'(a,l7)') trim(subname)//' remove_negative_runoff_glc = ', remove_negative_runoff_glc - write(logunit,'(a,l7)') trim(subname)//' spread_rofi = ', spread_rofi_nh - if (spread_rofi_nh) write(logunit,'(a)') trim(subname)//' rof2ocn_ice_spread = '//trim(rof2ocn_ice_spread) end if @@ -155,13 +142,6 @@ subroutine med_phases_post_rof(gcomp, rc) call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO) end if - ! unclear why this can't be in med_phases_post_rof_init, possibly pio not initialised - if ((spread_rofi_nh .or. spread_rofi_sh) .and. first_time) then - call med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, rof2ocn_ice_spread, comprof, rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - first_time=.false. - endif - nullify(is_local%wrap) call ESMF_GridCompGetInternalState(gcomp, is_local, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -195,23 +175,6 @@ subroutine med_phases_post_rof(gcomp, rc) end do end if - if (spread_rofi_nh .or. spread_rofi_sh) then - do n = 1, size(fields_to_spread_runoff) - call ESMF_FieldBundleGet(FBrof_r, fieldName=trim(fields_to_spread_runoff(n)), isPresent=exists, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) then - call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) - return - end if - if (exists) then - call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), FBrof_r, comprof, rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - else - call shr_log_error(string=trim(subname)//" Runoff field to spread: "//trim(fields_to_spread_runoff(n))//" does not exist", line=__LINE__,file=u_FILE_u, rc=rc) - return - end if - end do - end if - ! map rof to lnd if (is_local%wrap%med_coupling_active(comprof,complnd)) then call t_startf('MED:'//trim(subname)//' map_rof2lnd') @@ -252,6 +215,8 @@ subroutine med_phases_post_rof(gcomp, rc) call t_stopf('MED:'//trim(subname)//' map_rof2ice') end if + call med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_runoff, is_local%wrap%FBImp(comprof,compocn), compocn, rc) + ! Write rof inst, avg or aux if requested in mediator attributes call NUOPC_MediatorGet(gcomp, driverClock=dClock, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -459,7 +424,7 @@ subroutine med_phases_post_rof_remove_negative_runoff(gcomp, field_name, rc) end subroutine med_phases_post_rof_remove_negative_runoff - subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, rof2ocn_ice_spread, comp, rc) + subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, rofi_spread, comp, rc) !--------------------------------------------------------------- use med_io_mod , only : med_io_read use shr_reprosum_mod , only : shr_reprosum_calc @@ -467,7 +432,7 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runo ! input/output variables type(ESMF_GridComp) :: gcomp character(len=*), intent(in) :: fields_to_spread_runoff(:) - character(len=CL) :: rof2ocn_ice_spread + character(len=CL) :: rofi_spread integer, intent(in) :: comp integer, intent(out) :: rc @@ -481,7 +446,6 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runo real(r8), allocatable:: rof2ocn_a_weight(:,:) real(r8) :: global_sum(2) ! Antarctic, Greenland (frozen) runoff integer :: n, i, month, comm - logical :: error = .false. integer, parameter :: dbug_threshold = 0 ! threshold for writing debug information in this subroutine character(len=*), parameter :: subname='(med_phases_post_rof_mod: med_phases_post_rof_init_rof_spread_rofi)' @@ -532,7 +496,7 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runo if (dbug_flag > dbug_threshold) then call ESMF_LogWrite(trim(subname)//": trying to read rof2ocn_spread from file", ESMF_LOGMSG_INFO) endif - call med_io_read(rof2ocn_ice_spread, vm, FBrof_pattern, pre='pattern', ungridded_nc=.true., rc=rc) + call med_io_read(rofi_spread, vm, FBrof_pattern, pre='pattern', ungridded_nc=.true., rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return areas => is_local%wrap%mesh_info(comp)%areas @@ -568,29 +532,33 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runo if (global_sum(1) < (100.0_r8 * tiny(1.0_r8))) then if (maintask) write(logunit,*) trim(subname)//": In rof2ocn_spread file, "//& "Southern hemisphere sum is zero, or negative. Month = ",month, 'global_sum = ',global_sum(1) - error = .true. + spread_rofi_sh = .false. endif if (global_sum(2) < (100.0_r8 * tiny(1.0_r8))) then if (maintask) write(logunit,*) trim(subname)//": In rof2ocn_spread file, "//& "Northern hemisphere sum is zero, or negative. Month = ",month, 'global_sum = ',global_sum(2) - error = .true. + spread_rofi_nh = .false. endif ! adjust correction so that it's sums to 1 in each hemisphere - do i = 1, size(areas) - if (lats(i) < 0.0_r8) then - rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(1) - end if - end do - do i = 1, size(areas) - if (lats(i) >= 0.0_r8) then - rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(2) - end if - end do + if (spread_rofi_sh) then + do i = 1, size(areas) + if (lats(i) < 0.0_r8) then + rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(1) + end if + end do + end if + if (spread_rofi_nh) then + do i = 1, size(areas) + if (lats(i) >= 0.0_r8) then + rof2ocn_spread(i,month) = rof2ocn_spread(i,month) / global_sum(2) + end if + end do + end if enddo ! month - if (error) then + if ( .not. (spread_rofi_nh .or. spread_rofi_sh)) then call shr_log_error(string=trim(subname)//": error in rof2ocn_spread file, "//& "sum in each hemispheres is zero, or negative", line=__LINE__,file=u_FILE_u, rc=rc) return @@ -661,16 +629,20 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, field_bundle, comp allocate(rof2ocn_a_weight(size(runoff_flux),2)) rof2ocn_a_weight = 0.0_r8 - do n = 1, size(runoff_flux) - if (lats(n) < 0.0_r8) then - rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) - end if - end do - do n = 1, size(runoff_flux) - if (lats(n) >= 0.0_r8) then - rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) - end if - end do + if (spread_rofi_sh) then + do n = 1, size(runoff_flux) + if (lats(n) < 0.0_r8) then + rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) + end if + end do + end if + if (spread_rofi_nh) then + do n = 1, size(runoff_flux) + if (lats(n) >= 0.0_r8) then + rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) + end if + end do + end if ! Get the MPI communicator from the VM call ESMF_GridCompGet(gcomp, vm=vm, rc=rc) @@ -693,33 +665,41 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, field_bundle, comp if (ChkErr(rc,__LINE__,u_FILE_u)) return ! spread runoff by the saved pattern for the model month - do n = 1, size(runoff_flux) - if (lats(n) < 0.0_r8) then - runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(1) - end if - end do - - do n = 1, size(runoff_flux) - if (lats(n) >= 0.0_r8) then - runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(2) - end if - end do - - if (dbug_flag > dbug_threshold) then - - ! calculate the new global sum (after correction), difference should be equal to 0 - rof2ocn_a_weight = 0.0_r8 + if (spread_rofi_sh) then do n = 1, size(runoff_flux) if (lats(n) < 0.0_r8) then - rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) + runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(1) end if end do + end if + if (spread_rofi_nh) then do n = 1, size(runoff_flux) if (lats(n) >= 0.0_r8) then - rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) + runoff_flux(n) = rof2ocn_spread(n,mm) * global_sum(2) end if end do + end if + + if (dbug_flag > dbug_threshold) then + + ! calculate the new global sum (after correction), difference should be equal to 0 + rof2ocn_a_weight = 0.0_r8 + if (spread_rofi_sh) then + do n = 1, size(runoff_flux) + if (lats(n) < 0.0_r8) then + rof2ocn_a_weight(n,1) = areas(n) * runoff_flux(n) + end if + end do + end if + + if (spread_rofi_nh) then + do n = 1, size(runoff_flux) + if (lats(n) >= 0.0_r8) then + rof2ocn_a_weight(n,2) = areas(n) * runoff_flux(n) + end if + end do + end if call shr_reprosum_calc(rof2ocn_a_weight, global_sum, size(runoff_flux), size(runoff_flux), 2, & commid=comm) @@ -737,4 +717,58 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, field_bundle, comp end subroutine med_phases_post_rof_spread_rofi + subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_runoff, field_bundle, comp, rc) + + !--------------------------------------------------------------- + ! For a list of runoff fields, spread runoff according to the patterns prescribed in spread_rofi_weights. + use shr_reprosum_mod , only : shr_reprosum_calc + + ! input/output variables + type(ESMF_GridComp) :: gcomp + character(len=*), intent(in) :: fields_to_spread_runoff(:) + type(ESMF_FieldBundle) :: field_bundle + integer, intent(in) :: comp + integer, intent(out) :: rc + + character(len=CL) :: rofi_spread + + integer :: n + logical :: exists + + ! unclear why this can't be in med_phases_post_rof_init, possibly pio not initialised + if (.not. spreading_initialized) then + call NUOPC_CompAttributeGet(gcomp, name='rofi_spread', value=rofi_spread, isPresent=isPresent, isSet=isSet, rc=rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + if (isPresent .and. isSet) then + spread_rofi_nh = .true. + spread_rofi_sh = .true. + call med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runoff, rofi_spread, comp, rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + else + spread_rofi_nh = .false. + spread_rofi_sh = .false. + end if + + spreading_initialized = .true. + endif + + if (spread_rofi_nh .or. spread_rofi_sh) then + do n = 1, size(fields_to_spread_runoff) + call ESMF_FieldBundleGet(field_bundle, fieldName=trim(fields_to_spread_runoff(n)), isPresent=exists, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) then + call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) + return + end if + if (exists) then + call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), field_bundle, comp, rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + else + call shr_log_error(string=trim(subname)//" Runoff field to spread: "//trim(fields_to_spread_runoff(n))//" does not exist", line=__LINE__,file=u_FILE_u, rc=rc) + return + end if + end do + end if + + end subroutine med_phases_post_rof_spread_rofi_field_bundle + end module med_phases_post_rof_mod From 1510809782179ad503d4e673c8951a15dafaaa2d Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 16 Jun 2026 15:26:55 +1000 Subject: [PATCH 05/14] remove uneccesary changes --- mediator/med_phases_post_atm_mod.F90 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index d452859ef..a017bcace 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -12,7 +12,6 @@ module med_phases_post_atm_mod character(*), parameter :: u_FILE_u = & __FILE__ - logical :: first_time = .true. character(len=9), parameter :: fields_to_spread_runoff(1) = & ['Faoa_rofi'] @@ -27,7 +26,6 @@ subroutine med_phases_post_atm(gcomp, rc) !--------------------------------------- use NUOPC_Mediator , only : NUOPC_MediatorGet - use NUOPC , only : NUOPC_CompAttributeGet use ESMF , only : ESMF_Clock, ESMF_ClockIsCreated use ESMF , only : ESMF_GridComp, ESMF_GridCompGet, ESMF_FieldBundleGet use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_SUCCESS @@ -39,7 +37,6 @@ subroutine med_phases_post_atm(gcomp, rc) use med_utils_mod , only : chkerr => med_utils_ChkErr use med_internalstate_mod , only : compocn, compatm, compice, complnd, compwav, coupling_mode use perf_mod , only : t_startf, t_stopf - use shr_log_mod , only : shr_log_error use med_phases_post_rof_mod, only: med_phases_post_rof_spread_rofi_field_bundle ! input/output variables @@ -50,9 +47,6 @@ subroutine med_phases_post_atm(gcomp, rc) type(InternalState) :: is_local type(ESMF_Clock) :: dClock character(len=*), parameter :: subname='(med_phases_post_atm)' - character(len=CL) :: atm2ocn_ice_spread - logical :: isPresent, isSet - integer :: n !------------------------------------------------------------------------------- rc = ESMF_SUCCESS From 5797ecb6f0f9d859daf64fa1d1bc2b637349b2c2 Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 16 Jun 2026 15:35:02 +1000 Subject: [PATCH 06/14] add subroutine argument comment --- mediator/med_phases_post_rof_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index b6520dc72..f9d102840 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -433,7 +433,7 @@ subroutine med_phases_post_rof_init_rof_spread_rofi(gcomp, fields_to_spread_runo type(ESMF_GridComp) :: gcomp character(len=*), intent(in) :: fields_to_spread_runoff(:) character(len=CL) :: rofi_spread - integer, intent(in) :: comp + integer, intent(in) :: comp ! the component mesh the field is being spread on integer, intent(out) :: rc @@ -582,7 +582,7 @@ subroutine med_phases_post_rof_spread_rofi(gcomp, field_name, field_bundle, comp type(ESMF_GridComp) :: gcomp character(len=*), intent(in) :: field_name ! name of runoff flux field to process type(ESMF_FieldBundle) :: field_bundle - integer, intent(in) :: comp + integer, intent(in) :: comp ! the component mesh the field is being spread on integer, intent(out) :: rc ! local variables @@ -727,7 +727,7 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ type(ESMF_GridComp) :: gcomp character(len=*), intent(in) :: fields_to_spread_runoff(:) type(ESMF_FieldBundle) :: field_bundle - integer, intent(in) :: comp + integer, intent(in) :: comp ! the component mesh the field is being spread on integer, intent(out) :: rc character(len=CL) :: rofi_spread From bc1e91b7f47619cb2fd44335ddfe9c6c37fd236a Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 16 Jun 2026 16:03:12 +1000 Subject: [PATCH 07/14] declare variables --- mediator/med_phases_post_rof_mod.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index f9d102840..69086618b 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -733,7 +733,7 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ character(len=CL) :: rofi_spread integer :: n - logical :: exists + logical :: isPresent, isSet ! unclear why this can't be in med_phases_post_rof_init, possibly pio not initialised if (.not. spreading_initialized) then @@ -754,12 +754,12 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ if (spread_rofi_nh .or. spread_rofi_sh) then do n = 1, size(fields_to_spread_runoff) - call ESMF_FieldBundleGet(field_bundle, fieldName=trim(fields_to_spread_runoff(n)), isPresent=exists, rc=rc) + call ESMF_FieldBundleGet(field_bundle, fieldName=trim(fields_to_spread_runoff(n)), isPresent=isPresent, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) then call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) return end if - if (exists) then + if (isPresent) then call med_phases_post_rof_spread_rofi(gcomp, fields_to_spread_runoff(n), field_bundle, comp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return else From 85a2b4a3921d6b6f060a735d31608826bc01768f Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Tue, 16 Jun 2026 16:07:09 +1000 Subject: [PATCH 08/14] declare variables --- mediator/med_phases_post_rof_mod.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 69086618b..122e06277 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -730,11 +730,14 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ integer, intent(in) :: comp ! the component mesh the field is being spread on integer, intent(out) :: rc + ! local variables character(len=CL) :: rofi_spread - integer :: n logical :: isPresent, isSet + character(len=*), parameter :: subname='(med_phases_post_rof_mod: med_phases_post_rof_spread_rofi_field_bundle)' + !--------------------------------------- + ! unclear why this can't be in med_phases_post_rof_init, possibly pio not initialised if (.not. spreading_initialized) then call NUOPC_CompAttributeGet(gcomp, name='rofi_spread', value=rofi_spread, isPresent=isPresent, isSet=isSet, rc=rc) From 93501fcfcbd5d5635c47b1a97b3f51ff886065bc Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Wed, 17 Jun 2026 10:52:20 +1000 Subject: [PATCH 09/14] Update mediator/med_phases_post_rof_mod.F90 Co-authored-by: Anton Steketee <79179784+anton-seaice@users.noreply.github.com> --- mediator/med_phases_post_rof_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 122e06277..7aaece273 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -759,7 +759,7 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ do n = 1, size(fields_to_spread_runoff) call ESMF_FieldBundleGet(field_bundle, fieldName=trim(fields_to_spread_runoff(n)), isPresent=isPresent, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) then - call shr_log_error(string=trim(subname)//" Error checking field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) + call shr_log_error(string=trim(subname)//" Error getting field: "//trim(fields_to_spread_runoff(n)), line=__LINE__,file=u_FILE_u, rc=rc) return end if if (isPresent) then From effb2d785e9bb18ccd5f5bbc8ccc4222746a9068 Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Wed, 17 Jun 2026 10:52:31 +1000 Subject: [PATCH 10/14] Update mediator/med_phases_post_rof_mod.F90 Co-authored-by: Anton Steketee <79179784+anton-seaice@users.noreply.github.com> --- mediator/med_phases_post_rof_mod.F90 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 7aaece273..3197668a5 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -753,7 +753,12 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ end if spreading_initialized = .true. - endif +if (maintask) then + write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Greenland = ', spread_rofi_nh + write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Antarctic = ', spread_rofi_sh + if (spread_rofi_nh .or spread_rofi_sh) write(logunit,'(a)') trim(subname)//' rof2ocn_ice_spread = '//trim(rof2ocn_ice_spread) + end if +endif if (spread_rofi_nh .or. spread_rofi_sh) then do n = 1, size(fields_to_spread_runoff) From 25aeed3b2d90ea39420d4380b66b71a4ac6715c7 Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Wed, 17 Jun 2026 10:52:40 +1000 Subject: [PATCH 11/14] Update mediator/med_phases_post_atm_mod.F90 Co-authored-by: Anton Steketee <79179784+anton-seaice@users.noreply.github.com> --- mediator/med_phases_post_atm_mod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index a017bcace..8770fa886 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -129,6 +129,7 @@ subroutine med_phases_post_atm(gcomp, rc) end if if (trim(coupling_mode) == 'access-esm') then + # in access-esm, runoff comes from the atmosphere component, so spreading of iceberg melt here call med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_runoff, is_local%wrap%FBImp(compatm,compocn), compocn, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if From 8eff75472c0dc04971aa1ad4048072f0ee6b608c Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Wed, 17 Jun 2026 10:55:54 +1000 Subject: [PATCH 12/14] review response --- mediator/med_phases_post_atm_mod.F90 | 2 +- mediator/med_phases_post_rof_mod.F90 | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mediator/med_phases_post_atm_mod.F90 b/mediator/med_phases_post_atm_mod.F90 index 8770fa886..a4aeaf765 100644 --- a/mediator/med_phases_post_atm_mod.F90 +++ b/mediator/med_phases_post_atm_mod.F90 @@ -129,7 +129,7 @@ subroutine med_phases_post_atm(gcomp, rc) end if if (trim(coupling_mode) == 'access-esm') then - # in access-esm, runoff comes from the atmosphere component, so spreading of iceberg melt here + ! in access-esm, runoff comes from the atmosphere component, so spreading of iceberg melt here call med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_runoff, is_local%wrap%FBImp(compatm,compocn), compocn, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 3197668a5..1b799f076 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -753,12 +753,12 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ end if spreading_initialized = .true. -if (maintask) then - write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Greenland = ', spread_rofi_nh - write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Antarctic = ', spread_rofi_sh - if (spread_rofi_nh .or spread_rofi_sh) write(logunit,'(a)') trim(subname)//' rof2ocn_ice_spread = '//trim(rof2ocn_ice_spread) - end if -endif + if (maintask) then + write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Greenland = ', spread_rofi_nh + write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Antarctic = ', spread_rofi_sh + if (spread_rofi_nh .or. spread_rofi_sh) write(logunit,'(a)') trim(subname)//' rof2ocn_ice_spread = '//trim(rof2ocn_ice_spread) + end if + endif if (spread_rofi_nh .or. spread_rofi_sh) then do n = 1, size(fields_to_spread_runoff) From acfb66112039bf4b83e993baeb73127e2f218178 Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Wed, 17 Jun 2026 11:03:25 +1000 Subject: [PATCH 13/14] review response --- mediator/med_phases_post_rof_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 1b799f076..3c098aca2 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -756,7 +756,7 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ if (maintask) then write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Greenland = ', spread_rofi_nh write(logunit,'(a,l7)') trim(subname)//' spread_rofi_Antarctic = ', spread_rofi_sh - if (spread_rofi_nh .or. spread_rofi_sh) write(logunit,'(a)') trim(subname)//' rof2ocn_ice_spread = '//trim(rof2ocn_ice_spread) + if (spread_rofi_nh .or. spread_rofi_sh) write(logunit,'(a)') trim(subname)//' rofi_spread = '//trim(rofi_spread) end if endif From 076447a3d5eae55ee2b66d9412888331cfa299cb Mon Sep 17 00:00:00 2001 From: Kieran Ricardo Date: Wed, 17 Jun 2026 15:06:35 +1000 Subject: [PATCH 14/14] make spreading_initialized flag a local variable --- mediator/med_phases_post_rof_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediator/med_phases_post_rof_mod.F90 b/mediator/med_phases_post_rof_mod.F90 index 3c098aca2..0da447ceb 100644 --- a/mediator/med_phases_post_rof_mod.F90 +++ b/mediator/med_phases_post_rof_mod.F90 @@ -49,7 +49,6 @@ module med_phases_post_rof_mod logical :: remove_negative_runoff_lnd logical :: remove_negative_runoff_glc logical :: spread_rofi_nh, spread_rofi_sh - logical :: spreading_initialized = .false. character(len=9), parameter :: fields_to_remove_negative_runoff_lnd(2) = & ['Forr_rofl', & @@ -734,6 +733,7 @@ subroutine med_phases_post_rof_spread_rofi_field_bundle(gcomp, fields_to_spread_ character(len=CL) :: rofi_spread integer :: n logical :: isPresent, isSet + logical :: spreading_initialized = .false. character(len=*), parameter :: subname='(med_phases_post_rof_mod: med_phases_post_rof_spread_rofi_field_bundle)' !---------------------------------------