Skip to content

Commit

Permalink
Only allocate memory we plan to use
Browse files Browse the repository at this point in the history
Don't need to allocate memory in the diagnostic type for diagnostics that MOM6
is not including in any history files
  • Loading branch information
mnlevy1981 committed Nov 8, 2021
1 parent 1b67e5f commit c3ce30b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/tracer/MARBL_tracers.F90
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,10 @@ subroutine register_MARBL_diags(MARBL_diags, diag, day, G, id_diags)
day, &
trim(MARBL_diags%diags(m)%long_name), &
trim(MARBL_diags%diags(m)%units))
allocate(id_diags(m)%field_2d(SZI_(G),SZJ_(G)))
id_diags(m)%field_2d(:,:) = 0.
if (id_diags(m)%id > 0) then
allocate(id_diags(m)%field_2d(SZI_(G),SZJ_(G)))
id_diags(m)%field_2d(:,:) = 0.
end if
else ! 3D field
! TODO: MARBL should provide v_extensive through MARBL_diags
! (for now, FESEDFLUX is the only one that should be true)
Expand All @@ -711,8 +713,10 @@ subroutine register_MARBL_diags(MARBL_diags, diag, day, G, id_diags)
trim(MARBL_diags%diags(m)%long_name), &
trim(MARBL_diags%diags(m)%units), &
v_extensive=(trim(MARBL_diags%diags(m)%short_name).eq."FESEDFLUX"))
allocate(id_diags(m)%field_3d(SZI_(G),SZJ_(G), SZK_(G)))
id_diags(m)%field_3d(:,:,:) = 0.
if (id_diags(m)%id > 0) then
allocate(id_diags(m)%field_3d(SZI_(G),SZJ_(G), SZK_(G)))
id_diags(m)%field_3d(:,:,:) = 0.
end if
end if
end do

Expand Down Expand Up @@ -894,7 +898,8 @@ subroutine MARBL_tracers_column_physics(h_old, h_new, ea, eb, fluxes, dt, G, GV,
! * diagnostics
do m=1,size(MARBL_instances%surface_flux_diags%diags)
! All diags are 2D coming from surface
CS%surface_flux_diags(m)%field_2d(i,j) = real(MARBL_instances%surface_flux_diags%diags(m)%field_2d(1))
if (CS%surface_flux_diags(m)%id > 0) &
CS%surface_flux_diags(m)%field_2d(i,j) = real(MARBL_instances%surface_flux_diags%diags(m)%field_2d(1))
end do

! * Surface tracer flux
Expand Down Expand Up @@ -1084,15 +1089,17 @@ subroutine MARBL_tracers_column_physics(h_old, h_new, ea, eb, fluxes, dt, G, GV,

! * diagnostics
do m=1,size(MARBL_instances%interior_tendency_diags%diags)
if (allocated(CS%interior_tendency_diags(m)%field_2d)) then
! Only copy values if ref_depth < bathyT
if (G%bathyT(i,j) > real(MARBL_instances%interior_tendency_diags%diags(m)%ref_depth)) then
CS%interior_tendency_diags(m)%field_2d(i,j) = &
real(MARBL_instances%interior_tendency_diags%diags(m)%field_2d(1))
if (CS%interior_tendency_diags(m)%id > 0) then
if (allocated(CS%interior_tendency_diags(m)%field_2d)) then
! Only copy values if ref_depth < bathyT
if (G%bathyT(i,j) > real(MARBL_instances%interior_tendency_diags%diags(m)%ref_depth)) then
CS%interior_tendency_diags(m)%field_2d(i,j) = &
real(MARBL_instances%interior_tendency_diags%diags(m)%field_2d(1))
end if
else ! not a 2D diagnostic
CS%interior_tendency_diags(m)%field_3d(i,j,:) = &
real(MARBL_instances%interior_tendency_diags%diags(m)%field_3d(:,1))
end if
else
CS%interior_tendency_diags(m)%field_3d(i,j,:) = &
real(MARBL_instances%interior_tendency_diags%diags(m)%field_3d(:,1))
end if
end do
! * tendency values themselves (and vertical integrals of them)
Expand Down

0 comments on commit c3ce30b

Please sign in to comment.