diff --git a/src/control/cam_snapshot_common.F90 b/src/control/cam_snapshot_common.F90 index 6a342b67be..8fd659113b 100644 --- a/src/control/cam_snapshot_common.F90 +++ b/src/control/cam_snapshot_common.F90 @@ -1235,7 +1235,14 @@ subroutine cam_pbuf_snapshot_all_outfld(lchnk, file_num, pbuf) ! Retrieve the pbuf data. Special handling for certain ! integer-type fields. - if( trim(pbuf_snapshot(i)%ddt_string) == 'clubbtop') then + ! This will allow data written out to not be mangled, + ! and also allow writing out snapshots with debug on in GNU compiler. + if( trim(pbuf_snapshot(i)%ddt_string) == 'clubbtop' .or. & + trim(pbuf_snapshot(i)%ddt_string) == 'ZM_JT' .or. & + trim(pbuf_snapshot(i)%ddt_string) == 'ZM_MAXG' .or. & + trim(pbuf_snapshot(i)%ddt_string) == 'ZM_IDEEP' .or. & + trim(pbuf_snapshot(i)%ddt_string) == 'NMXRGN' .or. & + trim(pbuf_snapshot(i)%ddt_string) == 'ACNUNM') then call pbuf_get_field(pbuf, pbuf_idx, tmpptr2d_int) ! copy into real allocate(tmpptr2d(size(tmpptr2d_int, 1), size(tmpptr2d_int, 2))) diff --git a/src/physics/cam/physpkg.F90 b/src/physics/cam/physpkg.F90 index ad0837ea9b..2f0df4c81f 100644 --- a/src/physics/cam/physpkg.F90 +++ b/src/physics/cam/physpkg.F90 @@ -1531,6 +1531,12 @@ subroutine tphysac (ztodt, cam_in, & ifld = pbuf_get_index('AST') call pbuf_get_field(pbuf, ifld, ast, start=(/1,1,itim_old/), kount=(/pcols,pver,1/) ) + ! zero out local variables that may be written to snapshot for safety. + fh2o(:) = 0._r8 ! used in chem_timestep_tend. + surfric(:) = 0._r8 ! out from vertical_diffusion_tend. + obklen(:) = 0._r8 ! out from vertical_diffusion_tend. + flx_heat(:) = 0._r8 ! first out from gw_drag_cam. + ! ! accumulate fluxes into net flux array for spectral dycores ! jrm Include latent heat of fusion for snow @@ -2358,6 +2364,19 @@ subroutine tphysbc (ztodt, state, & call t_stopf('bc_init') + ! Zero-initialize subroutine-level variables for snapshot + cmfmc(:,:) = 0._r8 + cmfcme(:,:) = 0._r8 + zdu(:,:) = 0._r8 + rliq(:) = 0._r8 + rice(:) = 0._r8 + dlf(:,:) = 0._r8 + dlf2(:,:) = 0._r8 + rliq2(:) = 0._r8 + det_s(:) = 0._r8 + det_ice(:) = 0._r8 + net_flx(:) = 0._r8 + !=================================================== ! Global mean total energy fixer !=================================================== @@ -2515,10 +2534,6 @@ subroutine tphysbc (ztodt, state, & dlf(:,:) = 0._r8 end if - ! Zero-initialize subroutine-level variables for snapshot - dlf2(:,:) = 0._r8 - rliq2(:) = 0._r8 - if (trim(cam_take_snapshot_before) == "convect_shallow_tend") then call cam_snapshot_all_outfld_tphysbc(cam_snapshot_before_num, state, tend, cam_in, cam_out, pbuf, & flx_heat, cmfmc, cmfcme, zdu, rliq, rice, dlf, dlf2, rliq2, det_s, det_ice, net_flx) diff --git a/src/physics/cam7/physpkg.F90 b/src/physics/cam7/physpkg.F90 index a3f0c49fe6..c5dccb3647 100644 --- a/src/physics/cam7/physpkg.F90 +++ b/src/physics/cam7/physpkg.F90 @@ -1623,6 +1623,15 @@ subroutine tphysac (ztodt, cam_in, & call pbuf_get_field(pbuf, rliqbc_idx, rliqbc) rliq(:ncol) = rliqbc(:ncol) + ! zero out local variables that may be written to snapshot for safety. + fh2o(:) = 0._r8 ! used in chem_timestep_tend. + surfric(:) = 0._r8 ! out from vertical_diffusion_tend. + obklen(:) = 0._r8 ! out from vertical_diffusion_tend. + flx_heat(:) = 0._r8 ! first out from gw_drag_cam. + det_s(:) = 0._r8 ! out from clubb_tend_cam. + det_ice(:) = 0._r8 ! out from clubb_tend_cam. + net_flx(:) = 0._r8 ! out from radiation_tend. + ! ! accumulate fluxes into net flux array for spectral dycores ! jrm Include latent heat of fusion for snow @@ -2788,6 +2797,17 @@ subroutine tphysbc (ztodt, state, & call t_stopf('bc_init') + ! Zero-initialize subroutine-level variables for snapshot + cmfmc(:,:) = 0._r8 + cmfcme(:,:) = 0._r8 + zdu(:,:) = 0._r8 + rliq(:) = 0._r8 + rice(:) = 0._r8 + dlf(:,:) = 0._r8 + dlf2(:,:) = 0._r8 + rliq2(:) = 0._r8 + net_flx(:) = 0._r8 + !=================================================== ! Global mean total energy fixer !===================================================