85 subroutine rrtmgp_lw_main_run(doLWrad, doLWclrsky, top_at_1, doGP_lwscat, &
86 use_LW_jacobian, doGP_sgs_cnv, doGP_sgs_pbl, nCol, nLay, nGases,rrtmgp_phys_blksz,&
87 nGauss_angles, icseed_lw, iovr, iovr_convcld, iovr_max, iovr_maxrand, iovr_rand, &
88 iovr_dcorr, iovr_exp, iovr_exprand, isubc_lw, semis, tsfg, p_lay, p_lev, t_lay, &
89 t_lev, vmr_o2, vmr_h2o, vmr_o3, vmr_ch4, vmr_n2o, vmr_co2, &
90 cld_frac, cld_lwp, cld_reliq, cld_iwp, cld_reice, cld_swp, cld_resnow, &
91 cld_rwp, cld_rerain, precip_frac, cld_cnv_lwp, cld_cnv_reliq, cld_cnv_iwp, &
92 cld_cnv_reice, cld_pbl_lwp, cld_pbl_reliq, cld_pbl_iwp, cld_pbl_reice, &
93 cloud_overlap_param, active_gases_array, aerlw_tau, aerlw_ssa, aerlw_g, &
94 fluxlwUP_allsky, fluxlwDOWN_allsky, fluxlwUP_clrsky, fluxlwDOWN_clrsky, &
95 fluxlwUP_jac, fluxlwUP_radtime, fluxlwDOWN_radtime, errmsg, errflg)
98 logical,
intent(in) :: &
106 integer,
intent(in) :: &
121 integer,
intent(in),
dimension(:),
optional :: &
123 real(kind_phys),
dimension(:),
intent(in) :: &
126 real(kind_phys),
dimension(:,:),
intent(in),
optional :: &
137 real(kind_phys),
dimension(:,:),
intent(in) :: &
147 real(kind_phys),
dimension(:,:),
intent(in),
optional :: &
158 real(kind_phys),
dimension(:,:,:),
intent(in) :: &
162 character(len=*),
dimension(:),
intent(in),
optional :: &
166 real(kind_phys),
dimension(:,:),
intent(inout),
optional :: &
174 character(len=*),
intent(out) :: &
176 integer,
intent(out) :: &
180 type(ty_fluxes_byband) :: flux_allsky, flux_clrsky
181 integer :: icol, ilay, igas, iband, icol2, ix, iblck
182 integer,
dimension(rrtmgp_phys_blksz) :: ipseed_lw
184 real(kind_phys),
dimension(rrtmgp_phys_blksz) :: zcf0, zcf1
185 logical,
dimension(rrtmgp_phys_blksz,nLay,lw_gas_props%get_ngpt()) :: maskmcica
186 real(kind_phys),
dimension(rrtmgp_phys_blksz) :: tau_rain, tau_snow
187 real(kind_dbl_prec),
dimension(lw_gas_props%get_ngpt()) :: rng1d
188 real(kind_dbl_prec),
dimension(lw_gas_props%get_ngpt(),nLay,rrtmgp_phys_blksz) :: rng3d,rng3d2
189 real(kind_dbl_prec),
dimension(lw_gas_props%get_ngpt()*nLay) :: rng2d
190 real(kind_phys),
dimension(rrtmgp_phys_blksz,nLay+1,lw_gas_props%get_nband()),
target :: &
191 fluxlw_up_allsky, fluxlw_up_clrsky, fluxlw_dn_allsky, fluxlw_dn_clrsky
192 real(kind_phys),
dimension(rrtmgp_phys_blksz,lw_gas_props%get_ngpt()) :: lw_ds
193 real(kind_phys),
dimension(lw_gas_props%get_nband(),rrtmgp_phys_blksz) :: sfc_emiss_byband
196 type(ty_gas_concs) :: gas_concs
197 type(ty_optical_props_1scl) :: lw_optical_props_clrsky, lw_optical_props_aerosol_local
198 type(ty_optical_props_2str) :: lw_optical_props_clouds, lw_optical_props_cloudsbyband, &
199 lw_optical_props_cnvcloudsbyband, lw_optical_props_pblcloudsbyband, &
200 lw_optical_props_precipbyband
201 type(ty_source_func_lw) :: sources
207 if (.not. dolwrad)
return
214 call check_error_msg(
'rrtmgp_lw_main_gas_concs_run',gas_concs%init(active_gases_array))
217 call check_error_msg(
'rrtmgp_lw_main_gas_optics_run',&
218 lw_optical_props_clrsky%alloc_1scl(rrtmgp_phys_blksz, nlay, lw_gas_props))
219 call check_error_msg(
'rrtmgp_lw_main_sources_run',&
220 sources%alloc(rrtmgp_phys_blksz, nlay, lw_gas_props))
221 call check_error_msg(
'rrtmgp_lw_main_cloud_optics_run',&
222 lw_optical_props_cloudsbyband%alloc_2str(rrtmgp_phys_blksz, nlay, lw_gas_props%get_band_lims_wavenumber()))
223 call check_error_msg(
'rrtmgp_lw_main_precip_optics_run',&
224 lw_optical_props_precipbyband%alloc_2str(rrtmgp_phys_blksz, nlay, lw_gas_props%get_band_lims_wavenumber()))
225 call check_error_msg(
'rrtmgp_lw_mian_cloud_sampling_run', &
226 lw_optical_props_clouds%alloc_2str(rrtmgp_phys_blksz, nlay, lw_gas_props))
227 call check_error_msg(
'rrtmgp_lw_main_aerosol_optics_run',&
228 lw_optical_props_aerosol_local%alloc_1scl(rrtmgp_phys_blksz, nlay, lw_gas_props%get_band_lims_wavenumber()))
229 if (dogp_sgs_cnv)
then
230 call check_error_msg(
'rrtmgp_lw_main_cnv_cloud_optics_run',&
231 lw_optical_props_cnvcloudsbyband%alloc_2str(rrtmgp_phys_blksz, nlay, lw_gas_props%get_band_lims_wavenumber()))
233 if (dogp_sgs_pbl)
then
234 call check_error_msg(
'rrtmgp_lw_main_pbl_cloud_optics_run',&
235 lw_optical_props_pblcloudsbyband%alloc_2str(rrtmgp_phys_blksz, nlay, lw_gas_props%get_band_lims_wavenumber()))
243 do icol=1,ncol,rrtmgp_phys_blksz
244 icol2 = icol + rrtmgp_phys_blksz - 1
249 lw_optical_props_clrsky%tau = 0._kind_phys
250 lw_optical_props_precipbyband%tau = 0._kind_phys
251 lw_optical_props_precipbyband%ssa = 0._kind_phys
252 lw_optical_props_precipbyband%g = 0._kind_phys
253 lw_optical_props_cloudsbyband%tau = 0._kind_phys
254 lw_optical_props_cloudsbyband%ssa = 0._kind_phys
255 lw_optical_props_cloudsbyband%g = 0._kind_phys
256 lw_optical_props_clouds%tau = 0._kind_phys
257 lw_optical_props_clouds%ssa = 0._kind_phys
258 lw_optical_props_clouds%g = 0._kind_phys
259 sources%sfc_source = 0._kind_phys
260 sources%lay_source = 0._kind_phys
261 sources%lev_source_inc = 0._kind_phys
262 sources%lev_source_dec = 0._kind_phys
263 sources%sfc_source_Jac = 0._kind_phys
264 fluxlw_up_allsky = 0._kind_phys
265 fluxlw_dn_allsky = 0._kind_phys
266 fluxlw_up_clrsky = 0._kind_phys
267 fluxlw_dn_clrsky = 0._kind_phys
268 if (dogp_sgs_cnv) lw_optical_props_cnvcloudsbyband%tau = 0._kind_phys
269 if (dogp_sgs_pbl) lw_optical_props_pblcloudsbyband%tau = 0._kind_phys
272 fluxlw_up_allsky = 0._kind_phys
273 fluxlw_dn_allsky = 0._kind_phys
274 fluxlw_up_clrsky = 0._kind_phys
275 fluxlw_dn_clrsky = 0._kind_phys
276 flux_allsky%bnd_flux_up => fluxlw_up_allsky
277 flux_allsky%bnd_flux_dn => fluxlw_dn_allsky
278 flux_clrsky%bnd_flux_up => fluxlw_up_clrsky
279 flux_clrsky%bnd_flux_dn => fluxlw_dn_clrsky
286 call check_error_msg(
'rrtmgp_lw_main_set_vmr_o2', &
287 gas_concs%set_vmr(trim(active_gases_array(istr_o2)), vmr_o2(icol:icol2,:)))
288 call check_error_msg(
'rrtmgp_lw_main_set_vmr_co2', &
289 gas_concs%set_vmr(trim(active_gases_array(istr_co2)),vmr_co2(icol:icol2,:)))
290 call check_error_msg(
'rrtmgp_lw_main_set_vmr_ch4', &
291 gas_concs%set_vmr(trim(active_gases_array(istr_ch4)),vmr_ch4(icol:icol2,:)))
292 call check_error_msg(
'rrtmgp_lw_main_set_vmr_n2o', &
293 gas_concs%set_vmr(trim(active_gases_array(istr_n2o)),vmr_n2o(icol:icol2,:)))
294 call check_error_msg(
'rrtmgp_lw_main_set_vmr_h2o', &
295 gas_concs%set_vmr(trim(active_gases_array(istr_h2o)),vmr_h2o(icol:icol2,:)))
296 call check_error_msg(
'rrtmgp_lw_main_set_vmr_o3', &
297 gas_concs%set_vmr(trim(active_gases_array(istr_o3)), vmr_o3(icol:icol2,:)))
305 do iblck=1,rrtmgp_phys_blksz
306 if (semis(icol+iblck-1) > eps .and. semis(icol+iblck-1) <= 1._kind_phys)
then
307 do iband=1,lw_gas_props%get_nband()
308 sfc_emiss_byband(iband,iblck) = semis(icol+iblck-1)
311 sfc_emiss_byband(1:lw_gas_props%get_nband(),iblck) = 1.0
320 call check_error_msg(
'rrtmgp_lw_main_gas_optics',lw_gas_props%gas_optics(&
321 p_lay(icol:icol2,:), &
322 p_lev(icol:icol2,:), &
323 t_lay(icol:icol2,:), &
326 lw_optical_props_clrsky, &
328 tlev=t_lev(icol:icol2,:)))
336 zcf0(:) = 1._kind_phys
337 zcf1(:) = 1._kind_phys
338 do iblck = 1, rrtmgp_phys_blksz
340 zcf0(iblck) = min(zcf0(iblck), 1._kind_phys - cld_frac(icol+iblck-1,ilay))
342 if (zcf0(iblck) <= ftiny) zcf0(iblck) = 0._kind_phys
343 if (zcf0(iblck) > oneminus) zcf0(iblck) = 1._kind_phys
344 zcf1(iblck) = 1._kind_phys - zcf0(iblck)
347 if (any(zcf1 .gt. eps))
then
349 call check_error_msg(
'rrtmgp_lw_main_cloud_optics',lw_cloud_props%cloud_optics(&
350 cld_lwp(icol:icol2,:), &
351 cld_iwp(icol:icol2,:), &
352 cld_reliq(icol:icol2,:), &
353 cld_reice(icol:icol2,:), &
354 lw_optical_props_cloudsbyband))
357 if (dogp_sgs_cnv)
then
359 call check_error_msg(
'rrtmgp_lw_main_cnv_cloud_optics',lw_cloud_props%cloud_optics(&
360 cld_cnv_lwp(icol:icol2,:), &
361 cld_cnv_iwp(icol:icol2,:), &
362 cld_cnv_reliq(icol:icol2,:), &
363 cld_cnv_reice(icol:icol2,:), &
364 lw_optical_props_cnvcloudsbyband))
367 call check_error_msg(
'rrtmgp_lw_main_increment_cnvclouds_to_clouds',&
368 lw_optical_props_cnvcloudsbyband%increment(lw_optical_props_cloudsbyband))
372 if (dogp_sgs_pbl)
then
374 call check_error_msg(
'rrtmgp_lw_main_pbl_cloud_optics',lw_cloud_props%cloud_optics(&
375 cld_pbl_lwp(icol:icol2,:), &
376 cld_pbl_iwp(icol:icol2,:), &
377 cld_pbl_reliq(icol:icol2,:), &
378 cld_pbl_reice(icol:icol2,:), &
379 lw_optical_props_pblcloudsbyband))
382 call check_error_msg(
'rrtmgp_lw_main_increment_pblclouds_to_clouds',&
383 lw_optical_props_pblcloudsbyband%increment(lw_optical_props_cloudsbyband))
392 tau_rain(:) = 0._kind_phys
393 tau_snow(:) = 0._kind_phys
394 do ix=1,rrtmgp_phys_blksz
396 if (cld_frac(icol+ix-1,ilay) .gt. eps)
then
398 tau_rain(ix) = absrain*cld_rwp(icol+ix-1,ilay)
401 if (cld_swp(icol+ix-1,ilay) .gt. 0. .and. cld_resnow(icol+ix-1,ilay) .gt. 10._kind_phys)
then
402 tau_snow(ix) = abssnow0*1.05756*cld_swp(icol+ix-1,ilay)/cld_resnow(icol+ix-1,ilay)
406 do iband=1,lw_gas_props%get_nband()
407 lw_optical_props_precipbyband%tau(ix,ilay,iband) = tau_rain(ix) + tau_snow(ix)
413 call check_error_msg(
'rrtmgp_lw_main_increment_precip_to_clouds',&
414 lw_optical_props_precipbyband%increment(lw_optical_props_cloudsbyband))
422 if (any(zcf1 .gt. eps))
then
424 if(isubc_lw == 1)
then
425 do ix=1,rrtmgp_phys_blksz
426 ipseed_lw(ix) = lw_gas_props%get_ngpt() + icol + ix - 1
428 elseif (isubc_lw == 2)
then
429 do ix=1,rrtmgp_phys_blksz
430 ipseed_lw(ix) = icseed_lw(icol+ix-1)
435 do ix=1,rrtmgp_phys_blksz
438 if (iovr == iovr_max)
then
441 rng3d(:,ilay,ix) = rng1d
446 rng3d(:,ilay,ix) = rng1d
453 if (iovr == iovr_maxrand .or. iovr == iovr_rand .or. iovr == iovr_max)
then
454 call sampled_mask(real(rng3d,kind=kind_phys), cld_frac(icol:icol2,:), maskmcica)
457 if (iovr == iovr_dcorr)
then
458 do ix=1,rrtmgp_phys_blksz
462 rng3d2(:,:,ix) = reshape(source = rng2d,shape=[lw_gas_props%get_ngpt(),nlay])
465 call sampled_mask(real(rng3d,kind=kind_phys), cld_frac(icol:icol2,:), maskmcica, &
466 overlap_param = cloud_overlap_param(icol:icol2,1:nlay-1), randoms2 = real(rng3d2, kind=kind_phys))
469 if (iovr == iovr_exp .or. iovr == iovr_exprand)
then
470 call sampled_mask(real(rng3d,kind=kind_phys), cld_frac(icol:icol2,:), maskmcica, &
471 overlap_param = cloud_overlap_param(icol:icol2,1:nlay-1))
474 call check_error_msg(
'rrtmgp_lw_main_cloud_sampling',&
475 draw_samples(maskmcica, .true., &
476 lw_optical_props_cloudsbyband, lw_optical_props_clouds))
485 lw_optical_props_aerosol_local%tau = aerlw_tau(icol:icol2,:,:)
486 call check_error_msg(
'rrtmgp_lw_main_increment_aerosol_to_clrsky',&
487 lw_optical_props_aerosol_local%increment(lw_optical_props_clrsky))
491 call check_error_msg(
'rrtmgp_lw_main_opt_angle',&
492 lw_gas_props%compute_optimal_angles(lw_optical_props_clrsky,lw_ds))
493 if (ngauss_angles .gt. 1)
then
494 call check_error_msg(
'rrtmgp_lw_main_lw_rte_clrsky',rte_lw( &
495 lw_optical_props_clrsky, &
500 n_gauss_angles = ngauss_angles))
502 call check_error_msg(
'rrtmgp_lw_main_lw_rte_clrsky',rte_lw( &
503 lw_optical_props_clrsky, &
512 fluxlwup_clrsky(icol:icol2,:) = sum(flux_clrsky%bnd_flux_up, dim=3)
513 fluxlwdown_clrsky(icol:icol2,:) = sum(flux_clrsky%bnd_flux_dn, dim=3)
515 fluxlwup_clrsky(icol:icol2,:) = 0.0
516 fluxlwdown_clrsky(icol:icol2,:) = 0.0
535 if (dogp_lwscat)
then
537 call check_error_msg(
'rrtmgp_lw_main_increment_clrsky_to_clouds',&
538 lw_optical_props_clrsky%increment(lw_optical_props_clouds))
540 if (use_lw_jacobian)
then
542 call check_error_msg(
'rrtmgp_lw_main_lw_rte_allsky',rte_lw( &
543 lw_optical_props_clouds, &
548 n_gauss_angles = ngauss_angles, &
549 flux_up_jac = fluxlwup_jac))
551 call check_error_msg(
'rrtmgp_lw_main_lw_rte_allsky',rte_lw( &
552 lw_optical_props_clouds, &
557 n_gauss_angles = ngauss_angles))
562 call check_error_msg(
'rrtmgp_lw_main_increment_clouds_to_clrsky', &
563 lw_optical_props_clouds%increment(lw_optical_props_clrsky))
565 if (use_lw_jacobian)
then
567 call check_error_msg(
'rrtmgp_lw_rte_run',rte_lw( &
568 lw_optical_props_clrsky, &
573 n_gauss_angles = ngauss_angles, &
574 flux_up_jac = fluxlwup_jac))
576 call check_error_msg(
'rrtmgp_lw_rte_run',rte_lw( &
577 lw_optical_props_clrsky, &
582 n_gauss_angles = ngauss_angles))
587 fluxlwup_allsky(icol:icol2,:) = sum(flux_allsky%bnd_flux_up, dim=3)
588 fluxlwdown_allsky(icol:icol2,:) = sum(flux_allsky%bnd_flux_dn, dim=3)
591 fluxlwup_radtime(icol:icol2,:) = fluxlwup_allsky(icol:icol2,:)
592 fluxlwdown_radtime(icol:icol2,:) = fluxlwdown_allsky(icol:icol2,:)