From 2a24325c9736f3c9e2664bdd51294be3b94fc13f Mon Sep 17 00:00:00 2001 From: Raffaele Montuoro Date: Sat, 27 Feb 2021 18:22:15 -0600 Subject: [PATCH 1/3] Set proper intent for dummy argument. --- Process_Library/GOCART2G_Process.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Process_Library/GOCART2G_Process.F90 b/Process_Library/GOCART2G_Process.F90 index f7a325fb..24267d27 100644 --- a/Process_Library/GOCART2G_Process.F90 +++ b/Process_Library/GOCART2G_Process.F90 @@ -1226,7 +1226,7 @@ subroutine WetRemovalGOCART2G ( km, klid, n1, n2, bin_ind, cdt, aero_type, kin, integer, intent(in) :: bin_ind ! bin index (usually the loop iteration) real, intent(in) :: cdt ! chemistry model time-step [sec] character(len=*) :: aero_type - logical, intent(inout) :: KIN ! true for aerosol + logical, intent(in) :: KIN ! true for aerosol real, intent(in) :: grav ! gravity [m/sec^2] real, intent(in) :: fwet real, dimension(:,:,:), intent(inout) :: aerosol ! internal state aerosol [kg/kg] From a4bb0b5c911b2d69feb06e3d6571363d9a8e0325 Mon Sep 17 00:00:00 2001 From: Raffaele Montuoro Date: Mon, 1 Mar 2021 12:17:35 -0600 Subject: [PATCH 2/3] Use proper pointer argument to prevent memory corruption. --- .../NI2G_GridComp/NI2G_GridCompMod.F90 | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 b/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 index 98d55c3b..9064c15a 100644 --- a/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 +++ b/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 @@ -743,9 +743,10 @@ subroutine Run2 (GC, import, export, clock, RC) real, allocatable, dimension(:,:) :: drydepositionfrequency, dqa real :: fwet logical :: KIN - real, pointer, dimension(:,:) :: fluxout - real, pointer, dimension(:,:,:) :: fluxoutWT + real, allocatable, target, dimension(:,:,:) :: fluxoutWT real, allocatable, dimension(:,:,:,:) :: aerosol + real, pointer, dimension(:,:) :: flux_ptr + real, pointer, dimension(:,:,:) :: fluxWT_ptr type (ESMF_ALARM) :: alarm logical :: alarm_is_ringing @@ -883,34 +884,33 @@ subroutine Run2 (GC, import, export, clock, RC) !if(mapl_am_i_root()) print*,'NI2G NH4SD array = ',NH4SD - allocate(fluxout, mold=lwi, __STAT__) ! Nitrate bin 1 - settles like ammonium sulfate (rhflag = 3) rhflag = 3 - fluxout = 0. + nullify(flux_ptr) + if (associated(NISD)) flux_ptr => NISD(:,:,1) call Chem_SettlingSimpleOrig (self%km, self%klid, rhFlag, MAPL_GRAV, self%cdt, & 1.e-6*self%radius(nNO3an1), self%rhop(nNO3an1), & - NO3an1, t, airdens, rh2, delp, zle, fluxout, rc) - if (associated(NISD)) NISD(:,:,1) = fluxout + NO3an1, t, airdens, rh2, delp, zle, flux_ptr, rc) !if(mapl_am_i_root()) print*,'NI2G sum(NISD(:,:,1)) = ',sum(NISD(:,:,1)) !if(mapl_am_i_root()) print*,'NI2G sum(NO3an1) = ',sum(NO3an1) ! Nitrate bin 2 - settles like sea salt (rhflag = 2) rhflag = 2 - fluxout = 0. + nullify(flux_ptr) + if (associated(NISD)) flux_ptr => NISD(:,:,2) call Chem_SettlingSimpleOrig (self%km, self%klid, rhFlag, MAPL_GRAV, self%cdt, & 1.e-6*self%radius(nNO3an2), self%rhop(nNO3an2), & - NO3an2, t, airdens, rh2, delp, zle, fluxout, rc) - if (associated(NISD)) NISD(:,:,2) = fluxout + NO3an2, t, airdens, rh2, delp, zle, flux_ptr, rc) !if(mapl_am_i_root()) print*,'NI2G sum(NISD(:,:,2)) = ',sum(NISD(:,:,2)) !if(mapl_am_i_root()) print*,'NI2G sum(NO3an2) = ',sum(NO3an2) ! Nitrate bin 1 - settles like dust (rhflag = 0) rhflag = 0 - fluxout = 0. + nullify(flux_ptr) + if (associated(NISD)) flux_ptr => NISD(:,:,3) call Chem_SettlingSimpleOrig (self%km, self%klid, rhFlag, MAPL_GRAV, self%cdt, & 1.e-6*self%radius(nNO3an3), self%rhop(nNO3an3), & - NO3an3, t, airdens, rh2, delp, zle, fluxout, rc) - if (associated(NISD)) NISD(:,:,3) = fluxout + NO3an3, t, airdens, rh2, delp, zle, flux_ptr, rc) !if(mapl_am_i_root()) print*,'NI2G sum(NISD(:,:,3)) = ',sum(NISD(:,:,3)) !if(mapl_am_i_root()) print*,'NI2G ChemSet sum(NO3an3) = ',sum(NO3an3) @@ -985,26 +985,34 @@ subroutine Run2 (GC, import, export, clock, RC) ! NI Large-scale Wet Removal ! -------------------------- - allocate(fluxoutWT(ubound(t,1), ubound(t,2), 1), __STAT__) - fluxoutWT = 0. + if (associated(NH3WT) .or. associated(NH4WT)) then + allocate(fluxoutWT(ubound(t,1), ubound(t,2), 1), __STAT__) + end if ! NH3 KIN = .false. fwet = 1. + nullify(fluxWT_ptr) + if (associated(NH3WT)) fluxWT_ptr => fluxoutWT call WetRemovalGOCART2G (self%km, self%klid, self%nbins, self%nbins, 1, self%cdt, 'NH3', & KIN, MAPL_GRAV, fwet, NH3, ple, t, airdens, & - pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxoutWT, rc) - if (associated(NH3WT)) NH3WT = fluxoutWT(:,:,1) + pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxWT_ptr, rc) + if (associated(NH3WT)) NH3WT = fluxWT_ptr(:,:,1) !if(mapl_am_i_root()) print*,'NI2G sum(NH3WT) = ',sum(NH3WT) !if(mapl_am_i_root()) print*,'NI2G sum(NH3) = ',sum(NH3) ! NH4a - fluxoutWT = 0. KIN = .true. fwet = 1. + nullify(fluxWT_ptr) + if (associated(NH4WT)) fluxWT_ptr => fluxoutWT call WetRemovalGOCART2G(self%km, self%klid, self%nbins, self%nbins, 1, self%cdt, 'NH4a', & KIN, MAPL_GRAV, fwet, NH4a, ple, t, airdens, & - pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxoutWT, rc) - if (associated(NH4WT)) NH4WT = fluxoutWT(:,:,1) + pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxWT_ptr, rc) + if (associated(NH4WT)) NH4WT = fluxWT_ptr(:,:,1) + + if (allocated(fluxoutWT)) then + deallocate(fluxoutWT, __STAT__) + end if !if(mapl_am_i_root()) print*,'NI2G sum(NH4WT) = ',sum(NH4WT) !if(mapl_am_i_root()) print*,'NI2G sum(NH4) = ',sum(NH4a) From 049281a2a668bffa6a181399b4c8761114636111 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Fri, 5 Mar 2021 13:13:04 -0500 Subject: [PATCH 3/3] Fixed messed up RC from merge-conflict merge --- .../NI2G_GridComp/NI2G_GridCompMod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 b/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 index 6a869c19..41411505 100644 --- a/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 +++ b/ESMF/GOCART2G_GridComp/NI2G_GridComp/NI2G_GridCompMod.F90 @@ -891,7 +891,7 @@ subroutine Run2 (GC, import, export, clock, RC) if (associated(NISD)) flux_ptr => NISD(:,:,1) call Chem_SettlingSimpleOrig (self%km, self%klid, rhFlag, MAPL_GRAV, self%cdt, & 1.e-6*self%radius(nNO3an1), self%rhop(nNO3an1), & - NO3an1, t, airdens, rh2, delp, zle, flux_ptr, rc) + NO3an1, t, airdens, rh2, delp, zle, flux_ptr, __RC__) !if(mapl_am_i_root()) print*,'NI2G sum(NISD(:,:,1)) = ',sum(NISD(:,:,1)) !if(mapl_am_i_root()) print*,'NI2G sum(NO3an1) = ',sum(NO3an1) @@ -901,7 +901,7 @@ subroutine Run2 (GC, import, export, clock, RC) if (associated(NISD)) flux_ptr => NISD(:,:,2) call Chem_SettlingSimpleOrig (self%km, self%klid, rhFlag, MAPL_GRAV, self%cdt, & 1.e-6*self%radius(nNO3an2), self%rhop(nNO3an2), & - NO3an2, t, airdens, rh2, delp, zle, flux_ptr, rc) + NO3an2, t, airdens, rh2, delp, zle, flux_ptr, __RC__) !if(mapl_am_i_root()) print*,'NI2G sum(NISD(:,:,2)) = ',sum(NISD(:,:,2)) !if(mapl_am_i_root()) print*,'NI2G sum(NO3an2) = ',sum(NO3an2) @@ -911,7 +911,7 @@ subroutine Run2 (GC, import, export, clock, RC) if (associated(NISD)) flux_ptr => NISD(:,:,3) call Chem_SettlingSimpleOrig (self%km, self%klid, rhFlag, MAPL_GRAV, self%cdt, & 1.e-6*self%radius(nNO3an3), self%rhop(nNO3an3), & - NO3an3, t, airdens, rh2, delp, zle, flux_ptr, rc) + NO3an3, t, airdens, rh2, delp, zle, flux_ptr, __RC__) !if(mapl_am_i_root()) print*,'NI2G sum(NISD(:,:,3)) = ',sum(NISD(:,:,3)) !if(mapl_am_i_root()) print*,'NI2G ChemSet sum(NO3an3) = ',sum(NO3an3) @@ -996,7 +996,7 @@ subroutine Run2 (GC, import, export, clock, RC) if (associated(NH3WT)) fluxWT_ptr => fluxoutWT call WetRemovalGOCART2G (self%km, self%klid, self%nbins, self%nbins, 1, self%cdt, 'NH3', & KIN, MAPL_GRAV, fwet, NH3, ple, t, airdens, & - pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxWT_ptr, rc) + pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxWT_ptr, __RC__) if (associated(NH3WT)) NH3WT = fluxWT_ptr(:,:,1) !if(mapl_am_i_root()) print*,'NI2G sum(NH3WT) = ',sum(NH3WT) !if(mapl_am_i_root()) print*,'NI2G sum(NH3) = ',sum(NH3) @@ -1008,7 +1008,7 @@ subroutine Run2 (GC, import, export, clock, RC) if (associated(NH4WT)) fluxWT_ptr => fluxoutWT call WetRemovalGOCART2G(self%km, self%klid, self%nbins, self%nbins, 1, self%cdt, 'NH4a', & KIN, MAPL_GRAV, fwet, NH4a, ple, t, airdens, & - pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxWT_ptr, rc) + pfl_lsan, pfi_lsan, cn_prcp, ncn_prcp, fluxWT_ptr, __RC__) if (associated(NH4WT)) NH4WT = fluxWT_ptr(:,:,1) if (allocated(fluxoutWT)) then