@@ -76,11 +76,12 @@ module bulk_aerosol_state_mod
7676
7777 !- -----------------------------------------------------------------------------
7878 !- -----------------------------------------------------------------------------
79- function constructor (state ,pbuf ,list_idx ) result(newobj)
79+ function constructor (ncol , state ,pbuf ,list_idx ) result(newobj)
8080 ! REMOVECAM: host-model specific dimensions
8181 use ppgrid, only: pcols, pver
8282 ! REMOVECAM_END
8383
84+ integer , intent (in ) :: ncol
8485 type (physics_state), target :: state
8586 type (physics_buffer_desc), pointer :: pbuf(:)
8687 integer , intent (in ), optional :: list_idx
@@ -97,12 +98,17 @@ function constructor(state,pbuf,list_idx) result(newobj)
9798 newobj% state = > state
9899 newobj% pbuf = > pbuf
99100
101+ ! set number of active columns internally to prevent loops from accessing beyond
102+ ! meaningful data in arrays
103+ call newobj% set_ncol(ncol)
104+
100105 if (present (list_idx)) call newobj% set_list_idx(list_idx)
101106
102107 ! Allocate per-object workspace for derived number fields.
103108 ! Thread-safe: in CAM, each chunk has its own state object.
104109 allocate (newobj% num_work_(pcols, pver), stat= ierr)
105110 if (ierr /= 0 ) call endrun(' bulk_aerosol_state constructor: num_work_ allocation error' )
111+ newobj% num_work_(:,:) = 0._r8
106112 allocate (newobj% zero_fld_(pcols, pver), stat= ierr)
107113 if (ierr /= 0 ) call endrun(' bulk_aerosol_state constructor: zero_fld_ allocation error' )
108114 newobj% zero_fld_(:,:) = 0._r8
@@ -209,20 +215,24 @@ subroutine get_ambient_num(self, bin_ndx, num)
209215 real (r8 ), pointer :: mmr(:,:)
210216 real (r8 ) :: ntm
211217 character (len= 32 ) :: aname
218+ integer :: nc
212219
213220 ! Derive number mixing ratio from mass: num = mmr * num_to_mass_aer (* bam_sulfate_scale for sulfate).
214221 ! This matches the inline computation formerly in microp_aero.F90 and nucleate_ice_cam.F90.
215222 ! Computed into per-object workspace (num_work_); callers must use or copy before the next call.
223+ ! Only active columns (1:ncol) are computed to avoid FPE on uninitialised padding columns.
224+
225+ nc = self% ncol()
216226
217227 call rad_cnst_get_aer_mmr(self% list_idx_, bin_ndx, self% state, self% pbuf, mmr)
218228 call rad_aer_get_props(self% list_idx_, bin_ndx, num_to_mass_aer= ntm, aername= aname)
219229
220230 ! Apply bam_sulfate_scale to sulfate/volcanic aerosol
221231 select case ( to_lower( aname(:4 ) ) )
222232 case (' sulf' , ' volc' ) ! both treated as 'sulfate' in aero_props%get type.
223- self% num_work_(:,:) = mmr(:,:) * ntm * bam_sulfate_scale
233+ self% num_work_(:nc ,:) = mmr(:nc ,:) * ntm * bam_sulfate_scale
224234 case default
225- self% num_work_(:,:) = mmr(:,:) * ntm
235+ self% num_work_(:nc ,:) = mmr(:nc ,:) * ntm
226236 end select
227237
228238 num = > self% num_work_
0 commit comments