FV3 Bundle
sorad.F90
Go to the documentation of this file.
1 module soradmod
2 
3 IMPLICIT NONE
4 
5 PRIVATE
7 
8 contains
9 
10  subroutine sorad ( m , & !Number of soundings
11  np , & !Number of model levels
12  nb , & !Number of bands
13  cosz_dev , & !Cosine of solar zenith angle
14  pl_dev , & !Pressure (Pa)
15  ta_dev , & !Temperature (K)
16  wa_dev , & !Specific humidity (kgkg^-1)
17  oa_dev , & !Ozone (kgkg^-1)
18  co2 , & !CO2 (pppv)
19  cwc_dev , & !Cloud properties (kgkg^-1)
20  fcld_dev , & !Cloud fractions (1)
21  ict , & !Level index separating high and middle clouds
22  icb , & !Level index separating middle and low clouds
23  reff_dev , & !Moisture refflectivity properties
24  hk_uv , & !Solar UV constant
25  hk_ir , & !Solar IR constant
26  taua_dev , & !Aerosol optical thickness
27  ssaa_dev , & !Aerosol single scattering albedo
28  asya_dev , & !Aerosol asymmetry factor
29  rsuvbm_dev , & !Surface reflectivity in the UV+par for beam insolation
30  rsuvdf_dev , & !Surface reflectivity in the UV+par for diffuse insolation
31  rsirbm_dev , & !Surface reflectivity in the near-ir region for beam insolation
32  rsirdf_dev , & !Surface reflectivity in the near-ir region for diffuse insolation
33 !Outputs
34  flx_dev , & !
35 !Constants
36  cons_grav, &
37  wk_uv, zk_uv, ry_uv, &
38  xk_ir, ry_ir, &
39  cah, coa, &
40  aig_uv, awg_uv, arg_uv, &
41  aib_uv, awb_uv, arb_uv, &
42  aib_nir, awb_nir, arb_nir, &
43  aia_nir, awa_nir, ara_nir, &
44  aig_nir, awg_nir, arg_nir, &
45  caib, caif )
46 
47  IMPLICIT NONE
48 
49  ! Parameters
50  ! ----------
51 
52  integer, parameter :: nu = 43
53  integer, parameter :: nw = 37
54  integer, parameter :: nx = 62
55  integer, parameter :: ny = 101
56  integer, parameter :: nband_uv = 5
57  integer, parameter :: nk_ir = 10
58  integer, parameter :: nband_ir = 3
59 
60  integer, parameter :: nband = nband_uv + nband_ir
61 
62  real(8), parameter :: dsm = 0.602
63 
64 
65 !-----input values
66 
67 !-----input parameters
68 
69  integer m,np,ict,icb,nb
70  real(8) cosz_dev(m),pl_dev(m,np+1),ta_dev(m,np),wa_dev(m,np),oa_dev(m,np),co2
71  real(8) cwc_dev(m,np,4),fcld_dev(m,np),reff_dev(m,np,4), hk_uv(5),hk_ir(3,10)
72  real(8) rsuvbm_dev(m),rsuvdf_dev(m),rsirbm_dev(m),rsirdf_dev(m)
73 
74  real(8) taua_dev(m,np,nb)
75  real(8) ssaa_dev(m,np,nb)
76  real(8) asya_dev(m,np,nb)
77 
78  logical :: overcast
79 
80 ! Constants
81 real(8), intent(in) :: wk_uv(5), zk_uv(5), ry_uv(5)
82 real(8), intent(in) :: xk_ir(10), ry_ir(3)
83 real(8), intent(in) :: cah(43,37), coa(62,101)
84 
85 real(8), intent(in) :: aig_uv(3), awg_uv(3), arg_uv(3)
86 real(8), intent(in) :: aib_uv, awb_uv(2), arb_uv(2)
87 real(8), intent(in) :: aib_nir, awb_nir(3,2), arb_nir(3,2)
88 real(8), intent(in) :: aia_nir(3,3), awa_nir(3,3), ara_nir(3,3)
89 real(8), intent(in) :: aig_nir(3,3), awg_nir(3,3), arg_nir(3,3)
90 real(8), intent(in) :: caib(11,9,11), caif(9,11)
91 
92 real(8), intent(in) :: cons_grav
93 
94 !-----output parameters
95 
96  real(8) flx_dev(m,np+1),flc_dev(m,np+1)
97  real(8) flxu_dev(m,np+1),flcu_dev(m,np+1)
98  real(8) fdiruv_dev (m),fdifuv_dev (m)
99  real(8) fdirpar_dev(m),fdifpar_dev(m)
100  real(8) fdirir_dev (m),fdifir_dev (m)
101  real(8) flx_sfc_band_dev(m,nband)
102 
103 !-----temporary arrays
104 
105  integer :: i,j,k,l,in,ntop
106 
107  real(8) :: dp(np),wh(np),oh(np)
108  real(8) :: scal(np)
109  real(8) :: swh(np+1),so2(np+1),df(0:np+1)
110  real(8) :: scal0, wvtoa, o3toa, pa
111  real(8) :: snt,cnt,x,xx4,xtoa
112  real(8) :: dp_pa(np)
113 
114 !-----parameters for co2 transmission tables
115 
116  real(8) :: w1,dw,u1,du
117 
118  integer :: ib,rc
119  real(8) :: tauclb(np),tauclf(np),asycl(np)
120  real(8) :: taubeam(np,4),taudiff(np,4)
121  real(8) :: fcld_col(np)
122  real(8) :: cwc_col(np,4)
123  real(8) :: reff_col(np,4)
124  real(8) :: taurs,tauoz,tauwv
125  real(8) :: tausto,ssatau,asysto
126  real(8) :: tautob,ssatob,asytob
127  real(8) :: tautof,ssatof,asytof
128  real(8) :: rr(0:np+1,2),tt(0:np+1,2),td(0:np+1,2)
129  real(8) :: rs(0:np+1,2),ts(0:np+1,2)
130  real(8) :: fall(np+1),fclr(np+1),fsdir,fsdif
131  real(8) :: fupa(np+1),fupc(np+1)
132  real(8) :: cc1,cc2,cc3
133  real(8) :: rrt,ttt,tdt,rst,tst
134 
135  integer :: iv,ik
136  real(8) :: ssacl(np)
137 
138  integer :: im
139 
140  integer :: ic,iw
141  real(8) :: ulog,wlog,dc,dd,x0,x1,x2,y0,y1,y2,du2,dw2
142 
143  integer :: ih
144 
145  !if (overcast == true) then
146  !real(8) :: rra(0:np+1),rxa(0:np+1)
147  !real(8) :: ttaold,tdaold,rsaold
148  !real(8) :: ttanew,tdanew,rsanew
149  !else
150  real(8) :: rra(0:np+1,2,2),tta(0:np,2,2)
151  real(8) :: tda(0:np,2,2)
152  real(8) :: rsa(0:np,2,2),rxa(0:np+1,2,2)
153  !endif
154 
155  real(8) :: flxdn
156  real(8) :: fdndir,fdndif,fupdif
157  real(8) :: denm,yy
158 
159  integer :: is
160  real(8) :: ch,cm,ct
161 
162  integer :: foundtop
163  real(8) :: dftop
164 
165 !-----Variables for aerosols
166 
167  integer :: ii, jj, irhp1, an
168 
169  real(8) :: dum
170 
171 
172  run_loop: do i=1,m
173 
174  ntop = 0
175  fdndir = 0.0
176  fdndif = 0.0
177 
178 !-----Beginning of sorad code
179 
180 !-----wvtoa and o3toa are the water vapor and o3 amounts of the region
181 ! above the pl(1) level.
182 ! snt is the secant of the solar zenith angle
183 
184  snt = 1.0/cosz_dev(i)
185  xtoa = max(pl_dev(i,1),1.e-3)
186  scal0 = xtoa*(0.5*xtoa/300.)**.8
187  o3toa = 1.02*oa_dev(i,1)*xtoa*466.7 + 1.0e-8
188  wvtoa = 1.02*wa_dev(i,1)*scal0 * (1.0+0.00135*(ta_dev(i,1)-240.)) + 1.0e-9
189  swh(1) = wvtoa
190 
191  do k=1,np
192 
193 !-----compute layer thickness. indices for the surface level and
194 ! surface layer are np+1 and np, respectively.
195 
196  dp(k) = pl_dev(i,k+1)-pl_dev(i,k)
197  dp_pa(k) = dp(k) * 100. ! dp in pascals
198 
199 !-----compute scaled water vapor amount following Eqs. (3.3) and (3.5)
200 ! unit is g/cm**2
201 !
202  pa = 0.5*(pl_dev(i,k)+pl_dev(i,k+1))
203  scal(k) = dp(k)*(pa/300.)**.8
204  wh(k) = 1.02*wa_dev(i,k)*scal(k) * (1.+0.00135*(ta_dev(i,k)-240.)) + 1.e-9
205  swh(k+1)= swh(k)+wh(k)
206 
207 !-----compute ozone amount, unit is (cm-atm)stp
208 ! the number 466.7 is the unit conversion factor
209 ! from g/cm**2 to (cm-atm)stp
210 
211  oh(k) = 1.02*oa_dev(i,k)*dp(k)*466.7 + 1.e-8
212 
213 !-----Fill the reff, cwc, and fcld for the column
214 
215  fcld_col(k) = fcld_dev(i,k)
216  do l = 1, 4
217  reff_col(k,l) = reff_dev(i,k,l)
218  cwc_col(k,l) = cwc_dev(i,k,l)
219  end do
220 
221  end do
222 
223 !-----Initialize temporary arrays to zero to avoid UMR
224 
225  rr = 0.0
226  tt = 0.0
227  td = 0.0
228  rs = 0.0
229  ts = 0.0
230 
231  rra = 0.0
232  rxa = 0.0
233 
234 !if( OVERCAST == .false. ) then
235  tta = 0.0
236  tda = 0.0
237  rsa = 0.0
238 !endif
239 
240 !-----initialize fluxes for all-sky (flx), clear-sky (flc), and
241 ! flux reduction (df)
242 !
243  do k=1,np+1
244  flx_dev(i,k)=0.
245  flc_dev(i,k)=0.
246  flxu_dev(i,k)=0.
247  flcu_dev(i,k)=0.
248  end do
249 
250 !-----Initialize new per-band surface fluxes
251 
252  do ib = 1, nband
253  flx_sfc_band_dev(i,ib) = 0.
254  end do
255 
256 !-----Begin inline of SOLUV
257 
258 !-----compute solar uv and par fluxes
259 
260 !-----initialize fdiruv, fdifuv, surface reflectances and transmittances.
261 ! the reflectance and transmittance of the clear and cloudy portions
262 ! of a layer are denoted by 1 and 2, respectively.
263 ! cc is the maximum cloud cover in each of the high, middle, and low
264 ! cloud groups.
265 ! 1/dsm=1/cos(53) = 1.66
266 
267  fdiruv_dev(i)=0.0
268  fdifuv_dev(i)=0.0
269  rr(np+1,1)=rsuvbm_dev(i)
270  rr(np+1,2)=rsuvbm_dev(i)
271  rs(np+1,1)=rsuvdf_dev(i)
272  rs(np+1,2)=rsuvdf_dev(i)
273  td(np+1,1)=0.0
274  td(np+1,2)=0.0
275  tt(np+1,1)=0.0
276  tt(np+1,2)=0.0
277  ts(np+1,1)=0.0
278  ts(np+1,2)=0.0
279  rr(0,1)=0.0
280  rr(0,2)=0.0
281  rs(0,1)=0.0
282  rs(0,2)=0.0
283 ! td(0,1)=1.0
284 ! td(0,2)=1.0
285  tt(0,1)=1.0
286  tt(0,2)=1.0
287  ts(0,1)=1.0
288  ts(0,2)=1.0
289  cc1=0.0
290  cc2=0.0
291  cc3=0.0
292 
293 !-----options for scaling cloud optical thickness
294 
295 !if ( OVERCAST == .true. ) then
296 
297 !-----Compute cloud optical thickness. Eqs. (4.6) and (4.10) and
298 ! compute cloud asymmetry factor
299 ! Note: the cloud optical properties are assumed to be independent
300 ! of spectral bands in the UV and PAR regions.
301 ! for a mixture of ice and liquid particles.
302 ! Eqs.(4.6)-(4.8), (6.2)-(6.4)
303 !
304 ! The indices 1, 2, 3, 4 are for ice, water, rain, snow particles,
305 ! respectively.
306 
307 ! call getvistau1(np,cosz_dev(i),dp_pa,fcld_col,reff_col,cwc_col,0,0,&
308 ! taubeam,taudiff,asycl, &
309 ! aig_uv, awg_uv, arg_uv, &
310 ! aib_uv, awb_uv, arb_uv, &
311 ! aib_nir, awb_nir, arb_nir, &
312 ! aia_nir, awa_nir, ara_nir, &
313 ! aig_nir, awg_nir, arg_nir, &
314 ! caib, caif, &
315 ! CONS_GRAV )
316 
317 !else
318 
319 !-----Compute scaled cloud optical thickness. Eqs. (4.6) and (4.10) and
320 ! compute cloud asymmetry factor
321 ! Note: the cloud optical properties are assumed to be independent
322 ! of spectral bands in the UV and PAR regions.
323 ! for a mixture of ice and liquid particles.
324 ! Eqs.(4.6)-(4.8), (6.2)-(6.4)
325 !
326 ! The indices 1, 2, 3, 4 are for ice, water, rain, snow particles,
327 ! respectively.
328 
329  call getvistau1(np,cosz_dev(i),dp_pa,fcld_col,reff_col,cwc_col,ict,icb, &
330  taubeam,taudiff,asycl, &
331  aig_uv, awg_uv, arg_uv, &
332  aib_uv, awb_uv, arb_uv, &
333  aib_nir, awb_nir, arb_nir, &
334  aia_nir, awa_nir, ara_nir, &
335  aig_nir, awg_nir, arg_nir, &
336  caib, caif, &
337  cons_grav )
338 
339 !-----clouds within each of the high, middle, and low clouds are
340 ! assumed to be maximally overlapped, and the cloud cover (cc)
341 ! for a group (high, middle, or low) is the maximum cloud cover
342 ! of all the layers within a group
343 ! The cc1,2,3 are still needed in the flux calculations below
344 
345 !MAT---DO NOT FUSE THIS LOOP
346 !MAT---Loop must run to completion so that cc[1,2,3] are correct.
347  do k=1,np
348  if (k.lt.ict) then
349  cc1=max(cc1,fcld_dev(i,k))
350  elseif (k.lt.icb) then
351  cc2=max(cc2,fcld_dev(i,k))
352  else
353  cc3=max(cc3,fcld_dev(i,k))
354  end if
355  end do
356 !MAT---DO NOT FUSE THIS LOOP
357 
358 !endif !overcast
359 
360  do k=1,np
361  tauclb(k)=taubeam(k,1)+taubeam(k,2)+taubeam(k,3)+taubeam(k,4)
362  tauclf(k)=taudiff(k,1)+taudiff(k,2)+taudiff(k,3)+taudiff(k,4)
363  end do
364 
365 !-----integration over spectral bands
366 
367 !-----Compute optical thickness, single-scattering albedo and asymmetry
368 ! factor for a mixture of "na" aerosol types. [Eqs. (4.16)-(4.18)]
369 
370  do ib=1,nband_uv
371 
372 !-----compute direct beam transmittances of the layer above pl(1)
373 
374  td(0,1)=exp(-(wvtoa*wk_uv(ib)+o3toa*zk_uv(ib))/cosz_dev(i))
375  td(0,2)=td(0,1)
376 
377  do k=1,np
378 
379 !-----compute clear-sky optical thickness, single scattering albedo,
380 ! and asymmetry factor (Eqs. 6.2-6.4)
381 
382  taurs=ry_uv(ib)*dp(k)
383  tauoz=zk_uv(ib)*oh(k)
384  tauwv=wk_uv(ib)*wh(k)
385 
386  tausto=taurs+tauoz+tauwv+taua_dev(i,k,ib)+1.0e-7
387  ssatau=ssaa_dev(i,k,ib)+taurs
388  asysto=asya_dev(i,k,ib)
389 
390  tautob=tausto
391  asytob=asysto/ssatau
392  ssatob=ssatau/tautob+1.0e-8
393  ssatob=min(ssatob,0.999999)
394 
395 !-----for direct incident radiation
396 
397  call deledd(tautob,ssatob,asytob,cosz_dev(i),rrt,ttt,tdt)
398 
399 !-----diffuse incident radiation is approximated by beam radiation with
400 ! an incident angle of 53 degrees, Eqs. (6.5) and (6.6)
401 
402  call deledd(tautob,ssatob,asytob,dsm,rst,tst,dum)
403 
404  rr(k,1)=rrt
405  tt(k,1)=ttt
406  td(k,1)=tdt
407  rs(k,1)=rst
408  ts(k,1)=tst
409 
410 !-----compute reflectance and transmittance of the cloudy portion
411 ! of a layer
412 
413 !-----for direct incident radiation
414 ! The effective layer optical properties. Eqs. (6.2)-(6.4)
415 
416  tautob=tausto+tauclb(k)
417  ssatob=(ssatau+tauclb(k))/tautob+1.0e-8
418  ssatob=min(ssatob,0.999999)
419  asytob=(asysto+asycl(k)*tauclb(k))/(ssatob*tautob)
420 
421 !-----for diffuse incident radiation
422 
423  tautof=tausto+tauclf(k)
424  ssatof=(ssatau+tauclf(k))/tautof+1.0e-8
425  ssatof=min(ssatof,0.999999)
426  asytof=(asysto+asycl(k)*tauclf(k))/(ssatof*tautof)
427 
428 !-----for direct incident radiation
429 ! note that the cloud optical thickness is scaled differently
430 ! for direct and diffuse insolation, Eqs. (7.3) and (7.4).
431 
432  call deledd(tautob,ssatob,asytob,cosz_dev(i),rrt,ttt,tdt)
433 
434 !-----diffuse incident radiation is approximated by beam radiation
435 ! with an incident angle of 53 degrees, Eqs. (6.5) and (6.6)
436 
437  call deledd(tautof,ssatof,asytof,dsm,rst,tst,dum)
438 
439  rr(k,2)=rrt
440  tt(k,2)=ttt
441  td(k,2)=tdt
442  rs(k,2)=rst
443  ts(k,2)=tst
444  end do
445 
446 !-----flux calculations
447 ! initialize clear-sky flux (fclr), all-sky flux (fall),
448 ! and surface downward fluxes (fsdir and fsdif)
449 
450  do k=1,np+1
451  fclr(k)=0.0
452  fall(k)=0.0
453  fupa(k)=0.0
454  fupc(k)=0.0
455  end do
456 
457  fsdir=0.0
458  fsdif=0.0
459 
460 !if ( OVERCAST == .true. ) then
461 
462 !-----Inline CLDFLXY
463 
464 !-----for clear- and all-sky flux calculations when fractional
465 ! cloud cover is either 0 or 1.
466 
467 !-----layers are added one at a time, going up from the surface.
468 ! rra is the composite reflectance illuminated by beam radiation
469 ! rxa is the composite reflectance illuminated from above
470 ! by diffuse radiation
471 ! rra and rxa are computed from Eqs. (6.9) and (6.11)
472 
473 !-----compute transmittances and reflectances for a composite of
474 ! layers. layers are added one at a time, going down from the top.
475 ! tda is the composite direct transmittance illuminated by
476 ! beam radiation
477 ! tta is the composite total transmittance illuminated by
478 ! beam radiation
479 ! rsa is the composite reflectance illuminated from below
480 ! by diffuse radiation
481 ! tta and rsa are computed from Eqs. (6.10) and (6.12)
482 
483 !-----compute fluxes following Eq. (6.15) for fupdif and
484 ! Eq. (6.16) for (fdndir+fdndif)
485 
486 ! fdndir is the direct downward flux
487 ! fdndif is the diffuse downward flux
488 ! fupdif is the diffuse upward flux
489 
490 !-----ih=1 for clear sky; ih=2 for cloudy sky.
491 
492 !-----First set is ih = 1
493 ! rra(np+1)=rr(np+1,1)
494 ! rxa(np+1)=rs(np+1,1)
495 !
496 ! do k=np,0,-1
497 ! denm=ts(k,1)/(1.-rs(k,1)*rxa(k+1))
498 ! rra(k)=rr(k,1)+(td(k,1)*rra(k+1)+(tt(k,1)-td(k,1))*rxa(k+1))*denm
499 ! rxa(k)=rs(k,1)+ts(k,1)*rxa(k+1)*denm
500 ! end do
501 !
502 ! do k=1,np+1
503 ! if (k <= np) then
504 ! if (k == 1) then
505 ! tdaold = td(0,1)
506 ! ttaold = tt(0,1)
507 ! rsaold = rs(0,1)
508 !
509 ! tdanew = 0.0
510 ! ttanew = 0.0
511 ! rsanew = 0.0
512 ! end if
513 ! denm=ts(k,1)/(1.-rsaold*rs(k,1))
514 ! tdanew=tdaold*td(k,1)
515 ! ttanew=tdaold*tt(k,1)+(tdaold*rsaold*rr(k,1)+ttaold-tdaold)*denm
516 ! rsanew=rs(k,1)+ts(k,1)*rsaold*denm
517 ! end if
518 !
519 ! denm=1./(1.-rsaold*rxa(k))
520 ! fdndir=tdaold
521 ! xx4=tdaold*rra(k)
522 ! yy=ttaold-tdaold
523 ! fdndif=(xx4*rsaold+yy)*denm
524 ! fupdif=(xx4+yy*rxa(k))*denm
525 ! flxdn=fdndir+fdndif-fupdif
526 ! fupc(k)=fupdif
527 ! fclr(k)=flxdn
528 !
529 ! tdaold = tdanew
530 ! ttaold = ttanew
531 ! rsaold = rsanew
532 !
533 ! tdanew = 0.0
534 ! ttanew = 0.0
535 ! rsanew = 0.0
536 ! end do
537 !
538 !!-----Second set is ih = 2
539 !
540 ! rra(np+1)=rr(np+1,2)
541 ! rxa(np+1)=rs(np+1,2)
542 !
543 ! do k=np,0,-1
544 ! denm=ts(k,2)/(1.-rs(k,2)*rxa(k+1))
545 ! rra(k)=rr(k,2)+(td(k,2)*rra(k+1)+(tt(k,2)-td(k,2))*rxa(k+1))*denm
546 ! rxa(k)=rs(k,2)+ts(k,2)*rxa(k+1)*denm
547 ! end do
548 !
549 ! do k=1,np+1
550 ! if (k <= np) then
551 ! if (k == 1) then
552 ! tdaold = td(0,2)
553 ! ttaold = tt(0,2)
554 ! rsaold = rs(0,2)
555 
556 ! tdanew = 0.0
557 ! ttanew = 0.0
558 ! rsanew = 0.0
559 ! end if
560 ! denm=ts(k,2)/(1.-rsaold*rs(k,2))
561 ! tdanew=tdaold*td(k,2)
562 ! ttanew=tdaold*tt(k,2)+(tdaold*rsaold*rr(k,2)+ttaold-tdaold)*denm
563 ! rsanew=rs(k,2)+ts(k,2)*rsaold*denm
564 ! end if
565 !
566 ! denm=1./(1.-rsaold*rxa(k))
567 ! fdndir=tdaold
568 ! xx4=tdaold*rra(k)
569 ! yy=ttaold-tdaold
570 ! fdndif=(xx4*rsaold+yy)*denm
571 ! fupdif=(xx4+yy*rxa(k))*denm
572 ! flxdn=fdndir+fdndif-fupdif
573 !
574 ! fupa(k)=fupdif
575 ! fall(k)=flxdn
576 !
577 ! tdaold = tdanew
578 ! ttaold = ttanew
579 ! rsaold = rsanew
580 !
581 ! tdanew = 0.0
582 ! ttanew = 0.0
583 ! rsanew = 0.0
584 ! end do
585 !
586 ! fsdir=fdndir
587 ! fsdif=fdndif
588 !
589 !!-----End CLDFLXY inline
590 !
591 !else
592 
593 !-----for clear- and all-sky flux calculations when fractional
594 ! cloud cover is allowed to be between 0 and 1.
595 ! the all-sky flux, fall is the summation inside the brackets
596 ! of Eq. (7.11)
597 
598 !-----Inline CLDFLX
599 
600 !-----compute transmittances and reflectances for a composite of
601 ! layers. layers are added one at a time, going down from the top.
602 ! tda is the composite direct transmittance illuminated
603 ! by beam radiation
604 ! tta is the composite total transmittance illuminated by
605 ! beam radiation
606 ! rsa is the composite reflectance illuminated from below
607 ! by diffuse radiation
608 ! tta and rsa are computed from Eqs. (6.10) and (6.12)
609 
610 !-----To save memory space, tda, tta, and rsa are pre-computed
611 ! for k<icb. The dimension of these parameters is (m,np,2,2).
612 ! It would have been (m,np,2,2,2) if these parameters were
613 ! computed for all k's.
614 
615 !-----for high clouds
616 ! ih=1 for clear-sky condition, ih=2 for cloudy-sky condition
617 
618  do ih=1,2
619  tda(0,ih,1)=td(0,ih)
620  tta(0,ih,1)=tt(0,ih)
621  rsa(0,ih,1)=rs(0,ih)
622  tda(0,ih,2)=td(0,ih)
623  tta(0,ih,2)=tt(0,ih)
624  rsa(0,ih,2)=rs(0,ih)
625 
626  do k=1,ict-1
627  denm=ts(k,ih)/(1.-rsa(k-1,ih,1)*rs(k,ih))
628  tda(k,ih,1)=tda(k-1,ih,1)*td(k,ih)
629  tta(k,ih,1)=tda(k-1,ih,1)*tt(k,ih)+(tda(k-1,ih,1)*rsa(k-1,ih,1)&
630  *rr(k,ih)+tta(k-1,ih,1)-tda(k-1,ih,1))*denm
631  rsa(k,ih,1)=rs(k,ih)+ts(k,ih)*rsa(k-1,ih,1)*denm
632  tda(k,ih,2)=tda(k,ih,1)
633  tta(k,ih,2)=tta(k,ih,1)
634  rsa(k,ih,2)=rsa(k,ih,1)
635  end do ! k loop
636 
637 !-----for middle clouds
638 ! im=1 for clear-sky condition, im=2 for cloudy-sky condition
639 
640  do k=ict,icb-1
641  do im=1,2
642  denm=ts(k,im)/(1.-rsa(k-1,ih,im)*rs(k,im))
643  tda(k,ih,im)=tda(k-1,ih,im)*td(k,im)
644  tta(k,ih,im)=tda(k-1,ih,im)*tt(k,im)+(tda(k-1,ih,im)&
645  *rsa(k-1,ih,im)*rr(k,im)+tta(k-1,ih,im)-tda(k-1,ih,im))*denm
646  rsa(k,ih,im)=rs(k,im)+ts(k,im)*rsa(k-1,ih,im)*denm
647  end do ! im loop
648  end do ! k loop
649  end do ! ih loop
650 
651 !-----layers are added one at a time, going up from the surface.
652 ! rra is the composite reflectance illuminated by beam radiation
653 ! rxa is the composite reflectance illuminated from above
654 ! by diffuse radiation
655 ! rra and rxa are computed from Eqs. (6.9) and (6.11)
656 
657 !-----To save memory space, rra and rxa are pre-computed for k>=icb.
658 ! the dimension of these parameters is (m,np,2,2). It would have
659 ! been (m,np,2,2,2) if these parameters were computed for all k's.
660 
661 !-----for the low clouds
662 ! is=1 for clear-sky condition, is=2 for cloudy-sky condition
663 
664  do is=1,2
665  rra(np+1,1,is)=rr(np+1,is)
666  rxa(np+1,1,is)=rs(np+1,is)
667  rra(np+1,2,is)=rr(np+1,is)
668  rxa(np+1,2,is)=rs(np+1,is)
669 
670  do k=np,icb,-1
671  denm=ts(k,is)/(1.-rs(k,is)*rxa(k+1,1,is))
672  rra(k,1,is)=rr(k,is)+(td(k,is)*rra(k+1,1,is)+(tt(k,is)-td(k,is))&
673  *rxa(k+1,1,is))*denm
674  rxa(k,1,is)=rs(k,is)+ts(k,is)*rxa(k+1,1,is)*denm
675  rra(k,2,is)=rra(k,1,is)
676  rxa(k,2,is)=rxa(k,1,is)
677  end do ! k loop
678 
679 !-----for middle clouds
680 
681  do k=icb-1,ict,-1
682  do im=1,2
683  denm=ts(k,im)/(1.-rs(k,im)*rxa(k+1,im,is))
684  rra(k,im,is)=rr(k,im)+(td(k,im)*rra(k+1,im,is)+(tt(k,im)-td(k,im))&
685  *rxa(k+1,im,is))*denm
686  rxa(k,im,is)=rs(k,im)+ts(k,im)*rxa(k+1,im,is)*denm
687  end do ! im loop
688  end do ! k loop
689  end do ! is loop
690 
691 !-----integration over eight sky situations.
692 ! ih, im, is denote high, middle and low cloud groups.
693 
694  do ih=1,2
695 
696 !-----clear portion
697  if(ih.eq.1) then
698  ch=1.0-cc1
699 !-----cloudy portion
700  else
701  ch=cc1
702  end if
703 
704  do im=1,2
705 !-----clear portion
706  if(im.eq.1) then
707  cm=ch*(1.0-cc2)
708 !-----cloudy portion
709  else
710  cm=ch*cc2
711  end if
712 
713  do is=1,2
714 !-----clear portion
715  if(is.eq.1) then
716  ct=cm*(1.0-cc3)
717 !-----cloudy portion
718  else
719  ct=cm*cc3
720  end if
721 
722 !-----add one layer at a time, going down.
723 
724  do k=icb,np
725  denm=ts(k,is)/(1.-rsa(k-1,ih,im)*rs(k,is))
726  tda(k,ih,im)=tda(k-1,ih,im)*td(k,is)
727  tta(k,ih,im)=tda(k-1,ih,im)*tt(k,is)+(tda(k-1,ih,im)*rr(k,is)&
728  *rsa(k-1,ih,im)+tta(k-1,ih,im)-tda(k-1,ih,im))*denm
729  rsa(k,ih,im)=rs(k,is)+ts(k,is)*rsa(k-1,ih,im)*denm
730  end do ! k loop
731 
732 !-----add one layer at a time, going up.
733 
734  do k=ict-1,0,-1
735  denm=ts(k,ih)/(1.-rs(k,ih)*rxa(k+1,im,is))
736  rra(k,im,is)=rr(k,ih)+(td(k,ih)*rra(k+1,im,is)+(tt(k,ih)-td(k,ih))&
737  *rxa(k+1,im,is))*denm
738  rxa(k,im,is)=rs(k,ih)+ts(k,ih)*rxa(k+1,im,is)*denm
739  end do ! k loop
740 
741 !-----compute fluxes following Eq. (6.15) for fupdif and
742 ! Eq. (6.16) for (fdndir+fdndif)
743 
744 ! fdndir is the direct downward flux
745 ! fdndif is the diffuse downward flux
746 ! fupdif is the diffuse upward flux
747 
748  do k=1,np+1
749  denm=1./(1.-rsa(k-1,ih,im)*rxa(k,im,is))
750  fdndir=tda(k-1,ih,im)
751  xx4=tda(k-1,ih,im)*rra(k,im,is)
752  yy=tta(k-1,ih,im)-tda(k-1,ih,im)
753  fdndif=(xx4*rsa(k-1,ih,im)+yy)*denm
754  fupdif=(xx4+yy*rxa(k,im,is))*denm
755  flxdn=fdndir+fdndif-fupdif
756 
757 !-----summation of fluxes over all sky situations;
758 ! the term in the brackets of Eq. (7.11)
759 
760  if(ih.eq.1 .and. im.eq.1 .and. is.eq.1) then
761  fupc(k)=fupdif
762  fclr(k)=flxdn
763  end if
764  fupa(k)=fupa(k)+fupdif*ct
765  fall(k)=fall(k)+flxdn*ct
766  end do ! k loop
767  fsdir=fsdir+fdndir*ct
768  fsdif=fsdif+fdndif*ct
769  end do ! is loop
770  end do ! im loop
771  end do ! ih loop
772 
773 !-----End CLDFLX inline
774 
775 !endif !overcast
776 
777 !-----flux integration, Eq. (6.1)
778 
779  do k=1,np+1
780  flx_dev(i,k)=flx_dev(i,k)+fall(k)*hk_uv(ib)
781  flc_dev(i,k)=flc_dev(i,k)+fclr(k)*hk_uv(ib)
782  flxu_dev(i,k)=flxu_dev(i,k)+fupa(k)*hk_uv(ib)
783  flcu_dev(i,k)=flcu_dev(i,k)+fupc(k)*hk_uv(ib)
784  end do
785 
786 !-----get surface flux for each band
787  flx_sfc_band_dev(i,ib)=flx_sfc_band_dev(i,ib)+fall(np+1)*hk_uv(ib)
788 
789 !-----compute direct and diffuse downward surface fluxes in the UV
790 ! and par regions
791 
792  if(ib.lt.5) then
793  fdiruv_dev(i)=fdiruv_dev(i)+fsdir*hk_uv(ib)
794  fdifuv_dev(i)=fdifuv_dev(i)+fsdif*hk_uv(ib)
795  else
796  fdirpar_dev(i)=fsdir*hk_uv(ib)
797  fdifpar_dev(i)=fsdif*hk_uv(ib)
798  end if
799  end do
800 
801 !-----Inline SOLIR
802 
803 !-----compute and update solar ir fluxes
804 
805  fdirir_dev(i)=0.0
806  fdifir_dev(i)=0.0
807  rr(np+1,1)=rsirbm_dev(i)
808  rr(np+1,2)=rsirbm_dev(i)
809  rs(np+1,1)=rsirdf_dev(i)
810  rs(np+1,2)=rsirdf_dev(i)
811  td(np+1,1)=0.0
812  td(np+1,2)=0.0
813  tt(np+1,1)=0.0
814  tt(np+1,2)=0.0
815  ts(np+1,1)=0.0
816  ts(np+1,2)=0.0
817  rr(0,1)=0.0
818  rr(0,2)=0.0
819  rs(0,1)=0.0
820  rs(0,2)=0.0
821 ! td(0,1)=1.0
822 ! td(0,2)=1.0
823  tt(0,1)=1.0
824  tt(0,2)=1.0
825  ts(0,1)=1.0
826  ts(0,2)=1.0
827  cc1=0.0
828  cc2=0.0
829  cc3=0.0
830 
831 !-----integration over spectral bands
832 
833 !-----Compute cloud optical thickness. Eqs. (4.6) and (4.10)
834 ! The indices 1, 2, 3 are for ice, water, rain particles,
835 ! respectively.
836 
837  do ib=1,nband_ir
838  iv=ib+5
839 
840 !-----options for scaling cloud optical thickness
841 
842 !if ( OVERCAST == .true. ) then
843 
844 !-----Compute cloud optical thickness. Eqs. (4.6) and (4.10) and
845 ! compute cloud single scattering albedo and asymmetry factor
846 ! for a mixture of ice and liquid particles.
847 ! Eqs.(4.6)-(4.8), (6.2)-(6.4)
848 !
849 ! The indices 1, 2, 3, 4 are for ice, water, rain, snow particles,
850 ! respectively.
851 
852 ! call getnirtau1(ib,np,cosz_dev(i),dp_pa,fcld_col,reff_col,cwc_col,0,0,&
853 ! taubeam,taudiff,asycl,ssacl, &
854 ! aig_uv, awg_uv, arg_uv, &
855 ! aib_uv, awb_uv, arb_uv, &
856 ! aib_nir, awb_nir, arb_nir, &
857 ! aia_nir, awa_nir, ara_nir, &
858 ! aig_nir, awg_nir, arg_nir, &
859 ! caib, caif, &
860 ! CONS_GRAV )
861 
862 !else
863 
864 !-----Compute scaled cloud optical thickness. Eqs. (4.6) and (4.10) and
865 ! compute cloud single scattering albedo and asymmetry factor
866 ! for a mixture of ice and liquid particles.
867 ! Eqs.(4.6)-(4.8), (6.2)-(6.4)
868 !
869 ! The indices 1, 2, 3, 4 are for ice, water, rain, snow particles,
870 ! respectively.
871 
872  call getnirtau1(ib,np,cosz_dev(i),dp_pa,fcld_col,reff_col,cwc_col,ict,icb, &
873  taubeam,taudiff,asycl,ssacl, &
874  aig_uv, awg_uv, arg_uv, &
875  aib_uv, awb_uv, arb_uv, &
876  aib_nir, awb_nir, arb_nir, &
877  aia_nir, awa_nir, ara_nir, &
878  aig_nir, awg_nir, arg_nir, &
879  caib, caif, &
880  cons_grav )
881 
882 !-----clouds within each of the high, middle, and low clouds are
883 ! assumed to be maximally overlapped, and the cloud cover (cc)
884 ! for a group (high, middle, or low) is the maximum cloud cover
885 ! of all the layers within a group
886 
887 !MAT--DO NOT FUSE THIS LOOP
888 !MAT Loop must run to completion so that cc[1,2,3] are correct.
889  do k=1,np
890  if (k.lt.ict) then
891  cc1=max(cc1,fcld_dev(i,k))
892  elseif (k.lt.icb) then
893  cc2=max(cc2,fcld_dev(i,k))
894  else
895  cc3=max(cc3,fcld_dev(i,k))
896  end if
897  end do
898 !MAT--DO NOT FUSE THIS LOOP
899 
900 !endif !overcast
901 
902  do k=1,np
903  tauclb(k)=taubeam(k,1)+taubeam(k,2)+taubeam(k,3)+taubeam(k,4)
904  tauclf(k)=taudiff(k,1)+taudiff(k,2)+taudiff(k,3)+taudiff(k,4)
905  end do
906 
907 
908 !-----integration over the k-distribution function
909 
910  do ik=1,nk_ir
911 
912 !-----compute direct beam transmittances of the layer above pl(1)
913 
914  td(0,1)=exp(-wvtoa*xk_ir(ik)/cosz_dev(i))
915  td(0,2)=td(0,1)
916 
917  do k=1,np
918  taurs=ry_ir(ib)*dp(k)
919  tauwv=xk_ir(ik)*wh(k)
920 
921 !-----compute clear-sky optical thickness, single scattering albedo,
922 ! and asymmetry factor. Eqs.(6.2)-(6.4)
923 
924  tausto=taurs+tauwv+taua_dev(i,k,iv)+1.0e-7
925  ssatau=ssaa_dev(i,k,iv)+taurs+1.0e-8
926  asysto=asya_dev(i,k,iv)
927  tautob=tausto
928  asytob=asysto/ssatau
929  ssatob=ssatau/tautob+1.0e-8
930  ssatob=min(ssatob,0.999999)
931 
932 !-----Compute reflectance and transmittance of the clear portion
933 ! of a layer
934 
935 !-----for direct incident radiation
936 
937  call deledd(tautob,ssatob,asytob,cosz_dev(i),rrt,ttt,tdt)
938 
939 !-----diffuse incident radiation is approximated by beam radiation with
940 ! an incident angle of 53 degrees, Eqs. (6.5) and (6.6)
941 
942  call deledd(tautob,ssatob,asytob,dsm,rst,tst,dum)
943 
944  rr(k,1)=rrt
945  tt(k,1)=ttt
946  td(k,1)=tdt
947  rs(k,1)=rst
948  ts(k,1)=tst
949 
950 !-----compute reflectance and transmittance of the cloudy portion
951 ! of a layer
952 
953 !-----for direct incident radiation. Eqs.(6.2)-(6.4)
954 
955  tautob=tausto+tauclb(k)
956  ssatob=(ssatau+ssacl(k)*tauclb(k))/tautob+1.0e-8
957  ssatob=min(ssatob,0.999999)
958  asytob=(asysto+asycl(k)*ssacl(k)*tauclb(k))/(ssatob*tautob)
959 
960 !-----for diffuse incident radiation
961 
962  tautof=tausto+tauclf(k)
963  ssatof=(ssatau+ssacl(k)*tauclf(k))/tautof+1.0e-8
964  ssatof=min(ssatof,0.999999)
965  asytof=(asysto+asycl(k)*ssacl(k)*tauclf(k))/(ssatof*tautof)
966 
967 !-----for direct incident radiation
968 
969  call deledd(tautob,ssatob,asytob,cosz_dev(i),rrt,ttt,tdt)
970 
971 !-----diffuse incident radiation is approximated by beam radiation with
972 ! an incident angle of 53 degrees, Eqs.(6.5) and (6.6)
973 
974  call deledd(tautof,ssatof,asytof,dsm,rst,tst,dum)
975 
976  rr(k,2)=rrt
977  tt(k,2)=ttt
978  td(k,2)=tdt
979  rs(k,2)=rst
980  ts(k,2)=tst
981  end do
982 
983 !-----FLUX CALCULATIONS
984 
985 ! initialize clear-sky flux (fclr), all-sky flux (fall),
986 ! and surface downward fluxes (fsdir and fsdif)
987 
988  do k=1,np+1
989  fclr(k)=0.0
990  fall(k)=0.0
991  fupc(k)=0.0
992  fupa(k)=0.0
993  end do
994 
995  fsdir=0.0
996  fsdif=0.0
997 
998 !-----for clear- and all-sky flux calculations when fractional
999 ! cloud cover is either 0 or 1.
1000 
1001 !if ( OVERCAST == .true. ) then
1002 
1003 !-----Inline CLDFLXY
1004 
1005 !-----layers are added one at a time, going up from the surface.
1006 ! rra is the composite reflectance illuminated by beam radiation
1007 ! rxa is the composite reflectance illuminated from above
1008 ! by diffuse radiation
1009 ! rra and rxa are computed from Eqs. (6.9) and (6.11)
1010 
1011 !-----compute transmittances and reflectances for a composite of
1012 ! layers. layers are added one at a time, going down from the top.
1013 ! tda is the composite direct transmittance illuminated by
1014 ! beam radiation
1015 ! tta is the composite total transmittance illuminated by
1016 ! beam radiation
1017 ! rsa is the composite reflectance illuminated from below
1018 ! by diffuse radiation
1019 ! tta and rsa are computed from Eqs. (6.10) and (6.12)
1020 
1021 !-----compute fluxes following Eq. (6.15) for fupdif and
1022 ! Eq. (6.16) for (fdndir+fdndif)
1023 
1024 ! fdndir is the direct downward flux
1025 ! fdndif is the diffuse downward flux
1026 ! fupdif is the diffuse upward flux
1027 
1028 !-----ih=1 for clear sky; ih=2 for cloudy sky.
1029 
1030 !-----First set is ih = 1
1031 ! rra(np+1)=rr(np+1,1)
1032 ! rxa(np+1)=rs(np+1,1)
1033 !
1034 ! do k=np,0,-1
1035 ! denm=ts(k,1)/(1.-rs(k,1)*rxa(k+1))
1036 ! rra(k)=rr(k,1)+(td(k,1)*rra(k+1)+(tt(k,1)-td(k,1))*rxa(k+1))*denm
1037 ! rxa(k)=rs(k,1)+ts(k,1)*rxa(k+1)*denm
1038 ! end do
1039 !
1040 ! do k=1,np+1
1041 ! if (k <= np) then
1042 ! if (k == 1) then
1043 ! tdaold = td(0,1)
1044 ! ttaold = tt(0,1)
1045 ! rsaold = rs(0,1)
1046 !
1047 ! tdanew = 0.0
1048 ! ttanew = 0.0
1049 ! rsanew = 0.0
1050 ! end if
1051 ! denm=ts(k,1)/(1.-rsaold*rs(k,1))
1052 ! tdanew=tdaold*td(k,1)
1053 ! ttanew=tdaold*tt(k,1)+(tdaold*rsaold*rr(k,1)+ttaold-tdaold)*denm
1054 ! rsanew=rs(k,1)+ts(k,1)*rsaold*denm
1055 ! end if
1056 !
1057 ! denm=1./(1.-rsaold*rxa(k))
1058 ! fdndir=tdaold
1059 ! xx4=tdaold*rra(k)
1060 ! yy=ttaold-tdaold
1061 ! fdndif=(xx4*rsaold+yy)*denm
1062 ! fupdif=(xx4+yy*rxa(k))*denm
1063 ! flxdn=fdndir+fdndif-fupdif
1064 !
1065 ! fupc(k)=fupdif
1066 ! fclr(k)=flxdn
1067 !
1068 ! tdaold = tdanew
1069 ! ttaold = ttanew
1070 ! rsaold = rsanew
1071 !
1072 ! tdanew = 0.0
1073 ! ttanew = 0.0
1074 ! rsanew = 0.0
1075 ! end do
1076 !
1077 !!-----Second set is ih = 2
1078 !
1079 ! rra(np+1)=rr(np+1,2)
1080 ! rxa(np+1)=rs(np+1,2)
1081 !
1082 ! do k=np,0,-1
1083 ! denm=ts(k,2)/(1.-rs(k,2)*rxa(k+1))
1084 ! rra(k)=rr(k,2)+(td(k,2)*rra(k+1)+(tt(k,2)-td(k,2))*rxa(k+1))*denm
1085 ! rxa(k)=rs(k,2)+ts(k,2)*rxa(k+1)*denm
1086 ! end do
1087 !
1088 ! do k=1,np+1
1089 ! if (k <= np) then
1090 ! if (k == 1) then
1091 ! tdaold = td(0,2)
1092 ! ttaold = tt(0,2)
1093 ! rsaold = rs(0,2)
1094 !
1095 ! tdanew = 0.0
1096 ! ttanew = 0.0
1097 ! rsanew = 0.0
1098 ! end if
1099 ! denm=ts(k,2)/(1.-rsaold*rs(k,2))
1100 ! tdanew=tdaold*td(k,2)
1101 ! ttanew=tdaold*tt(k,2)+(tdaold*rsaold*rr(k,2)+ttaold-tdaold)*denm
1102 ! rsanew=rs(k,2)+ts(k,2)*rsaold*denm
1103 ! end if
1104 !
1105 ! denm=1./(1.-rsaold*rxa(k))
1106 ! fdndir=tdaold
1107 ! xx4=tdaold*rra(k)
1108 ! yy=ttaold-tdaold
1109 ! fdndif=(xx4*rsaold+yy)*denm
1110 ! fupdif=(xx4+yy*rxa(k))*denm
1111 ! flxdn=fdndir+fdndif-fupdif
1112 !
1113 ! fupa(k)=fupdif
1114 ! fall(k)=flxdn
1115 !
1116 ! tdaold = tdanew
1117 ! ttaold = ttanew
1118 ! rsaold = rsanew
1119 !
1120 ! tdanew = 0.0
1121 ! ttanew = 0.0
1122 ! rsanew = 0.0
1123 ! end do
1124 !
1125 ! fsdir=fdndir
1126 ! fsdif=fdndif
1127 !
1128 !!-----End CLDFLXY inline
1129 !
1130 !else
1131 
1132 !-----for clear- and all-sky flux calculations when fractional
1133 ! cloud cover is allowed to be between 0 and 1.
1134 ! the all-sky flux, fall is the summation inside the brackets
1135 ! of Eq. (7.11)
1136 
1137 !-----Inline CLDFLX
1138 
1139 !-----compute transmittances and reflectances for a composite of
1140 ! layers. layers are added one at a time, going down from the top.
1141 ! tda is the composite direct transmittance illuminated
1142 ! by beam radiation
1143 ! tta is the composite total transmittance illuminated by
1144 ! beam radiation
1145 ! rsa is the composite reflectance illuminated from below
1146 ! by diffuse radiation
1147 ! tta and rsa are computed from Eqs. (6.10) and (6.12)
1148 
1149 !-----To save memory space, tda, tta, and rsa are pre-computed
1150 ! for k<icb. The dimension of these parameters is (m,np,2,2).
1151 ! It would have been (m,np,2,2,2) if these parameters were
1152 ! computed for all k's.
1153 
1154 !-----for high clouds
1155 ! ih=1 for clear-sky condition, ih=2 for cloudy-sky condition
1156 
1157  do ih=1,2
1158  tda(0,ih,1)=td(0,ih)
1159  tta(0,ih,1)=tt(0,ih)
1160  rsa(0,ih,1)=rs(0,ih)
1161  tda(0,ih,2)=td(0,ih)
1162  tta(0,ih,2)=tt(0,ih)
1163  rsa(0,ih,2)=rs(0,ih)
1164 
1165  do k=1,ict-1
1166  denm=ts(k,ih)/(1.-rsa(k-1,ih,1)*rs(k,ih))
1167  tda(k,ih,1)=tda(k-1,ih,1)*td(k,ih)
1168  tta(k,ih,1)=tda(k-1,ih,1)*tt(k,ih)+(tda(k-1,ih,1)*rsa(k-1,ih,1)&
1169  *rr(k,ih)+tta(k-1,ih,1)-tda(k-1,ih,1))*denm
1170  rsa(k,ih,1)=rs(k,ih)+ts(k,ih)*rsa(k-1,ih,1)*denm
1171  tda(k,ih,2)=tda(k,ih,1)
1172  tta(k,ih,2)=tta(k,ih,1)
1173  rsa(k,ih,2)=rsa(k,ih,1)
1174  end do ! k loop
1175 
1176 !-----for middle clouds
1177 ! im=1 for clear-sky condition, im=2 for cloudy-sky condition
1178 
1179  do k=ict,icb-1
1180  do im=1,2
1181  denm=ts(k,im)/(1.-rsa(k-1,ih,im)*rs(k,im))
1182  tda(k,ih,im)=tda(k-1,ih,im)*td(k,im)
1183  tta(k,ih,im)=tda(k-1,ih,im)*tt(k,im)+(tda(k-1,ih,im)&
1184  *rsa(k-1,ih,im)*rr(k,im)+tta(k-1,ih,im)-tda(k-1,ih,im))*denm
1185  rsa(k,ih,im)=rs(k,im)+ts(k,im)*rsa(k-1,ih,im)*denm
1186  end do ! im loop
1187  end do ! k loop
1188  end do ! ih loop
1189 
1190 !-----layers are added one at a time, going up from the surface.
1191 ! rra is the composite reflectance illuminated by beam radiation
1192 ! rxa is the composite reflectance illuminated from above
1193 ! by diffuse radiation
1194 ! rra and rxa are computed from Eqs. (6.9) and (6.11)
1195 
1196 !-----To save memory space, rra and rxa are pre-computed for k>=icb.
1197 ! the dimension of these parameters is (m,np,2,2). It would have
1198 ! been (m,np,2,2,2) if these parameters were computed for all k's.
1199 
1200 !-----for the low clouds
1201 ! is=1 for clear-sky condition, is=2 for cloudy-sky condition
1202 
1203  do is=1,2
1204  rra(np+1,1,is)=rr(np+1,is)
1205  rxa(np+1,1,is)=rs(np+1,is)
1206  rra(np+1,2,is)=rr(np+1,is)
1207  rxa(np+1,2,is)=rs(np+1,is)
1208 
1209  do k=np,icb,-1
1210  denm=ts(k,is)/(1.-rs(k,is)*rxa(k+1,1,is))
1211  rra(k,1,is)=rr(k,is)+(td(k,is)*rra(k+1,1,is)+(tt(k,is)-td(k,is))&
1212  *rxa(k+1,1,is))*denm
1213  rxa(k,1,is)=rs(k,is)+ts(k,is)*rxa(k+1,1,is)*denm
1214  rra(k,2,is)=rra(k,1,is)
1215  rxa(k,2,is)=rxa(k,1,is)
1216  end do ! k loop
1217 
1218 !-----for middle clouds
1219 
1220  do k=icb-1,ict,-1
1221  do im=1,2
1222  denm=ts(k,im)/(1.-rs(k,im)*rxa(k+1,im,is))
1223  rra(k,im,is)=rr(k,im)+(td(k,im)*rra(k+1,im,is)+(tt(k,im)-td(k,im))&
1224  *rxa(k+1,im,is))*denm
1225  rxa(k,im,is)=rs(k,im)+ts(k,im)*rxa(k+1,im,is)*denm
1226  end do ! im loop
1227  end do ! k loop
1228  end do ! is loop
1229 
1230 !-----integration over eight sky situations.
1231 ! ih, im, is denote high, middle and low cloud groups.
1232 
1233  do ih=1,2
1234 !-----clear portion
1235  if(ih.eq.1) then
1236  ch=1.0-cc1
1237 !-----cloudy portion
1238  else
1239  ch=cc1
1240  end if
1241 
1242  do im=1,2
1243 !-----clear portion
1244  if(im.eq.1) then
1245  cm=ch*(1.0-cc2)
1246 !-----cloudy portion
1247  else
1248  cm=ch*cc2
1249  end if
1250 
1251  do is=1,2
1252 !-----clear portion
1253  if(is.eq.1) then
1254  ct=cm*(1.0-cc3)
1255 !-----cloudy portion
1256  else
1257  ct=cm*cc3
1258  end if
1259 
1260 !-----add one layer at a time, going down.
1261 
1262  do k=icb,np
1263  denm=ts(k,is)/(1.-rsa(k-1,ih,im)*rs(k,is))
1264  tda(k,ih,im)=tda(k-1,ih,im)*td(k,is)
1265  tta(k,ih,im)=tda(k-1,ih,im)*tt(k,is)+(tda(k-1,ih,im)*rr(k,is)&
1266  *rsa(k-1,ih,im)+tta(k-1,ih,im)-tda(k-1,ih,im))*denm
1267  rsa(k,ih,im)=rs(k,is)+ts(k,is)*rsa(k-1,ih,im)*denm
1268  end do ! k loop
1269 
1270 !-----add one layer at a time, going up.
1271 
1272  do k=ict-1,0,-1
1273  denm=ts(k,ih)/(1.-rs(k,ih)*rxa(k+1,im,is))
1274  rra(k,im,is)=rr(k,ih)+(td(k,ih)*rra(k+1,im,is)+(tt(k,ih)-td(k,ih))&
1275  *rxa(k+1,im,is))*denm
1276  rxa(k,im,is)=rs(k,ih)+ts(k,ih)*rxa(k+1,im,is)*denm
1277  end do ! k loop
1278 
1279 !-----compute fluxes following Eq. (6.15) for fupdif and
1280 ! Eq. (6.16) for (fdndir+fdndif)
1281 ! fdndir is the direct downward flux
1282 ! fdndif is the diffuse downward flux
1283 ! fupdif is the diffuse upward flux
1284 
1285  do k=1,np+1
1286  denm=1./(1.-rsa(k-1,ih,im)*rxa(k,im,is))
1287  fdndir=tda(k-1,ih,im)
1288  xx4=tda(k-1,ih,im)*rra(k,im,is)
1289  yy=tta(k-1,ih,im)-tda(k-1,ih,im)
1290  fdndif=(xx4*rsa(k-1,ih,im)+yy)*denm
1291  fupdif=(xx4+yy*rxa(k,im,is))*denm
1292  flxdn=fdndir+fdndif-fupdif
1293 
1294 !-----summation of fluxes over all sky situations;
1295 ! the term in the brackets of Eq. (7.11)
1296 
1297  if(ih.eq.1 .and. im.eq.1 .and. is.eq.1) then
1298  fupc(k)=fupdif
1299  fclr(k)=flxdn
1300  end if
1301  fupa(k)=fupa(k)+fupdif*ct
1302  fall(k)=fall(k)+flxdn*ct
1303  end do ! k loop
1304  fsdir=fsdir+fdndir*ct
1305  fsdif=fsdif+fdndif*ct
1306  end do ! is loop
1307  end do ! im loop
1308  end do ! ih loop
1309 
1310 !-----End CLDFLX inline
1311 !endif !overcast
1312 
1313 !-----flux integration following Eq. (6.1)
1314 
1315  do k=1,np+1
1316  flx_dev(i,k)=flx_dev(i,k)+fall(k)*hk_ir(ib,ik)
1317  flc_dev(i,k)=flc_dev(i,k)+fclr(k)*hk_ir(ib,ik)
1318  flxu_dev(i,k)=flxu_dev(i,k)+fupa(k)*hk_ir(ib,ik)
1319  flcu_dev(i,k)=flcu_dev(i,k)+fupc(k)*hk_ir(ib,ik)
1320  end do
1321 
1322 !-----compute downward surface fluxes in the ir region
1323 
1324  fdirir_dev(i)=fdirir_dev(i)+fsdir*hk_ir(ib,ik)
1325  fdifir_dev(i)=fdifir_dev(i)+fsdif*hk_ir(ib,ik)
1326 
1327 !-----tabulate surface flux at ir bands
1328  flx_sfc_band_dev(i,iv)=flx_sfc_band_dev(i,iv)+fall(np+1)*hk_ir(ib,ik)
1329 
1330  end do ! ik loop
1331  end do
1332 
1333 !-----compute pressure-scaled o2 amount following Eq. (3.5) with f=1.
1334 ! unit is (cm-atm)stp. 165.22 = (1000/980)*23.14%*(22400/32)
1335 ! compute flux reduction due to oxygen following Eq. (3.18). 0.0633 is the
1336 ! fraction of insolation contained in the oxygen bands
1337 
1338  df(0) = 0.0
1339  cnt = 165.22*snt
1340  so2(1) = scal0*cnt
1341 ! LLT increased parameter 145 to 155 to enhance effect
1342  df(1) = 0.0633*(1.-exp(-0.000155*sqrt(so2(1))))
1343 
1344  do k=1,np
1345  so2(k+1) = so2(k) + scal(k)*cnt
1346 ! LLT increased parameter 145 to 155 to enhance effect
1347  df(k+1) = 0.0633*(1.0 - exp(-0.000155*sqrt(so2(k+1))))
1348  end do
1349 
1350 !-----for solar heating due to co2 scaling follows Eq(3.5) with f=1.
1351 ! unit is (cm-atm)stp. 789 = (1000/980)*(44/28.97)*(22400/44)
1352 
1353  so2(1) = (789.*co2)*scal0
1354 
1355  do k=1,np
1356  so2(k+1) = so2(k) + (789.*co2)*scal(k)
1357  end do
1358 
1359 !-----The updated flux reduction for co2 absorption in Band 7 where absorption due to
1360 ! water vapor and co2 are both moderate. df is given by the second term on the
1361 ! right-hand-side of Eq. (3.24) divided by So. so2 and swh are the co2 and
1362 ! water vapor amounts integrated from the top of the atmosphere
1363 
1364  u1 = -3.0
1365  du = 0.15
1366  w1 = -4.0
1367  dw = 0.15
1368 
1369 !-----Inline RFLX
1370  du2=du*du
1371  dw2=dw*dw
1372  x0=u1+real(nu)*du
1373  y0=w1+real(nw)*dw
1374 
1375  x1=u1-0.5*du
1376  y1=w1-0.5*dw
1377 
1378  do k= 1, np+1
1379  ulog=min(log10(so2(k)*snt),x0)
1380  wlog=min(log10(swh(k)*snt),y0)
1381  ic=int((ulog-x1)/du+1.)
1382  iw=int((wlog-y1)/dw+1.)
1383  if(ic.lt.2) ic=2
1384  if(iw.lt.2) iw=2
1385  if(ic.gt.nu) ic=nu
1386  if(iw.gt.nw) iw=nw
1387  dc=ulog-real(ic-2)*du-u1
1388  dd=wlog-real(iw-2)*dw-w1
1389  x2=cah(ic-1,iw-1)+(cah(ic-1,iw)-cah(ic-1,iw-1))/dw*dd
1390  y2=x2+(cah(ic,iw-1)-cah(ic-1,iw-1))/du*dc
1391  y2=max(y2,0.0)
1392  df(k)=df(k)+1.5*y2 ! LLT increase CO2 effect to help reduce cold tropopause bias
1393  end do
1394 
1395 !-----df is the updated flux reduction for co2 absorption
1396 ! in Band 8 where the co2 absorption has a large impact
1397 ! on the heating of middle atmosphere. From the table
1398 ! given by Eq. (3.19)
1399 
1400  u1 = 0.000250
1401  du = 0.000050
1402  w1 = -2.0
1403  dw = 0.05
1404 
1405 !-----Inline RFLX
1406  du2=du*du
1407  dw2=dw*dw
1408  x0=u1+real(nx)*du
1409  y0=w1+real(ny)*dw
1410 
1411  x1=u1-0.5*du
1412  y1=w1-0.5*dw
1413 
1414  do k= 1, np+1
1415  ulog=min(co2*snt,x0)
1416  wlog=min(log10(pl_dev(i,k)),y0)
1417  ic=int((ulog-x1)/du+1.)
1418  iw=int((wlog-y1)/dw+1.)
1419  if(ic.lt.2) ic=2
1420  if(iw.lt.2) iw=2
1421  if(ic.gt.nx) ic=nx
1422  if(iw.gt.ny) iw=ny
1423  dc=ulog-real(ic-2)*du-u1
1424  dd=wlog-real(iw-2)*dw-w1
1425  x2=coa(ic-1,iw-1)+(coa(ic-1,iw)-coa(ic-1,iw-1))/dw*dd
1426  y2=x2+(coa(ic,iw-1)-coa(ic-1,iw-1))/du*dc
1427  y2=max(y2,0.0)
1428  df(k)=df(k)+1.5*y2 ! LLT increase CO2 effect to help reduce cold tropopause bias
1429  end do
1430 
1431 !-----adjust the o2-co2 reduction below cloud top following Eq. (6.18)
1432 
1433  foundtop = 0
1434 
1435  do k=1,np
1436  if (fcld_dev(i,k) > 0.02.and.foundtop.eq.0) then
1437  foundtop = 1
1438  ntop = k
1439  end if
1440  end do
1441 
1442  if (foundtop.eq.0) ntop=np+1
1443 
1444  dftop = df(ntop)
1445 
1446  do k=1,np+1
1447  if (k .gt. ntop) then
1448  xx4 = (flx_dev(i,k)/flx_dev(i,ntop))
1449  df(k) = dftop + xx4 * (df(k)-dftop)
1450  end if
1451  end do
1452 
1453 !-----update the net fluxes
1454 
1455  do k=1,np+1
1456  df(k) = min(df(k),flx_dev(i,k)-1.0e-8)
1457 ! df(k) = 0.0
1458  flx_dev(i,k) = flx_dev(i,k) - df(k)
1459  flc_dev(i,k) = flc_dev(i,k) - df(k)
1460  end do
1461 
1462 !-----update the downward surface fluxes
1463 
1464 ! xx4 = fdirir (i) + fdifir (i) +&
1465 ! fdiruv (i) + fdifuv (i) +&
1466 ! fdirpar(i) + fdifpar(i)
1467 
1468  xx4 = flx_dev(i,np+1) + df(np+1)
1469 
1470  if ( abs(xx4) > epsilon(1.0) ) then
1471  xx4 = max(min(1.0 - df(np+1)/xx4,1.),0.)
1472  else
1473  xx4 = 0.0
1474  end if
1475 
1476  fdirir_dev(i) = xx4*fdirir_dev(i)
1477  fdifir_dev(i) = xx4*fdifir_dev(i)
1478  fdiruv_dev(i) = xx4*fdiruv_dev(i)
1479  fdifuv_dev(i) = xx4*fdifuv_dev(i)
1480  fdirpar_dev(i) = xx4*fdirpar_dev(i)
1481  fdifpar_dev(i) = xx4*fdifpar_dev(i)
1482 
1483  do ib = 1, nband
1484  flx_sfc_band_dev(i,ib) = xx4*flx_sfc_band_dev(i,ib)
1485  end do
1486 
1487  end do run_loop
1488 
1489  end subroutine sorad
1490 
1491 
1492 !*********************************************************************
1493 
1494  subroutine deledd(tau1,ssc1,g01,cza1,rr1,tt1,td1)
1496 !*********************************************************************
1497 !
1498 !-----uses the delta-eddington approximation to compute the
1499 ! bulk scattering properties of a single layer
1500 ! coded following King and Harshvardhan (JAS, 1986)
1501 !
1502 ! inputs:
1503 ! tau1: optical thickness
1504 ! ssc1: single scattering albedo
1505 ! g01: asymmetry factor
1506 ! cza1: cosine o the zenith angle
1507 !
1508 ! outputs:
1509 !
1510 ! rr1: reflection of the direct beam
1511 ! tt1: total (direct+diffuse) transmission of the direct beam
1512 ! td1: direct transmission of the direct beam
1513 !
1514 !*********************************************************************
1515 
1516  implicit none
1517 
1518  integer,parameter :: real_de = 8 ! 8 byte real
1519  !integer,parameter :: REAL_SP = 4 ! 4 byte real
1520 
1521 !-----input parameters
1522 
1523  real(8), intent(in) :: tau1,ssc1,g01,cza1
1524 
1525 !-----output parameters
1526 
1527  real(8), intent(out) :: rr1, tt1, td1
1528 
1529 !-----temporary parameters
1530 
1531  real(8), parameter :: zero = 0.0_real_de
1532  real(8), parameter :: one = 1.0_real_de
1533  real(8), parameter :: two = 2.0_real_de
1534  real(8), parameter :: three = 3.0_real_de
1535  real(8), parameter :: four = 4.0_real_de
1536  real(8), parameter :: fourth = 0.25_real_de
1537  real(8), parameter :: seven = 7.0_real_de
1538  real(8), parameter :: thresh = 1.e-8_real_de
1539 
1540  real(8) :: tau,ssc,g0,rr,tt,td
1541  real(8) :: zth,ff,xx,taup,sscp,gp,gm1,gm2,gm3,akk,alf1,alf2
1542  real(8) :: all,bll,st7,st8,cll,dll,fll,ell,st1,st2,st3,st4
1543 
1544  !zth = real(cza1,kind=REAL_DE)
1545  !g0 = real(g01 ,kind=REAL_DE)
1546  !tau = real(tau1,kind=REAL_DE)
1547  !ssc = real(ssc1,kind=REAL_DE)
1548 
1549  zth = dble(cza1)
1550  g0 = dble(g01)
1551  tau = dble(tau1)
1552  ssc = dble(ssc1)
1553 
1554  ff = g0*g0
1555  xx = one-ff*ssc
1556  taup= tau*xx
1557  sscp= ssc*(one-ff)/xx
1558  gp = g0/(one+g0)
1559 
1560  xx = three*gp
1561  gm1 = (seven-sscp*(four+xx))*fourth
1562  gm2 =-(one -sscp*(four-xx))*fourth
1563 
1564  akk = sqrt((gm1+gm2)*(gm1-gm2))
1565 
1566  xx = akk*zth
1567  st7 = one-xx
1568  st8 = one+xx
1569  st3 = st7*st8
1570 
1571  if (abs(st3) .lt. thresh) then
1572  zth = zth+0.0010
1573  if(zth > 1.0) zth = zth-0.0020
1574  xx = akk*zth
1575  st7 = one-xx
1576  st8 = one+xx
1577  st3 = st7*st8
1578  end if
1579 
1580  td=exp(-taup/zth)
1581 
1582  gm3 = (two-zth*three*gp)*fourth
1583  xx = gm1-gm2
1584  alf1= gm1-gm3*xx
1585  alf2= gm2+gm3*xx
1586 
1587  xx = akk*two
1588  all = (gm3-alf2*zth )*xx*td
1589  bll = (one-gm3+alf1*zth)*xx
1590 
1591  xx = akk*gm3
1592  cll = (alf2+xx)*st7
1593  dll = (alf2-xx)*st8
1594 
1595  xx = akk*(one-gm3)
1596  fll = (alf1+xx)*st8
1597  ell = (alf1-xx)*st7
1598 
1599  st2 = exp(-akk*taup)
1600  st4 = st2*st2
1601 
1602  st1 = sscp/((akk+gm1+(akk-gm1)*st4)*st3)
1603 
1604  rr = ( cll-dll*st4 - all*st2)*st1
1605  tt =-((fll-ell*st4)*td - bll*st2)*st1
1606 
1607  rr = max(rr,zero)
1608  tt = max(tt,zero)
1609 
1610  tt = tt+td
1611 
1612  !td1 = real(td,kind=REAL_SP)
1613  !rr1 = real(rr,kind=REAL_SP)
1614  !tt1 = real(tt,kind=REAL_SP)
1615  td1 = real(td)
1616  rr1 = real(rr)
1617  tt1 = real(tt)
1618 
1619  end subroutine deledd
1620 
1621 
1622  subroutine getvistau1(nlevs,cosz,dp,fcld,reff,hydromets,ict,icb, &
1623  taubeam,taudiff,asycl, &
1624  aig_uv, awg_uv, arg_uv, &
1625  aib_uv, awb_uv, arb_uv, &
1626  aib_nir, awb_nir, arb_nir, &
1627  aia_nir, awa_nir, ara_nir, &
1628  aig_nir, awg_nir, arg_nir, &
1629  caib, caif, &
1630  CONS_GRAV )
1632 ! !USES:
1633 
1634  implicit none
1635 
1636 ! !INPUT PARAMETERS:
1637  integer, intent(IN ) :: nlevs ! Number of levels
1638  real(8), intent(IN ) :: cosz ! Cosine of solar zenith angle
1639  real(8), intent(IN ) :: dp(nlevs) ! Delta pressure (Pa)
1640  real(8), intent(IN ) :: fcld(nlevs) ! Cloud fraction (used sometimes)
1641  real(8), intent(IN ) :: reff(nlevs,4) ! Effective radius (microns)
1642  real(8), intent(IN ) :: hydromets(nlevs,4) ! Hydrometeors (kg/kg)
1643  integer, intent(IN ) :: ict, icb ! Flags for various uses
1644 ! ict = 0 Indicates that in-cloud values have been given
1645 ! and are expected
1646 ! ict != 0 Indicates that overlap computation is needed, and:
1647 ! ict is the level of the mid-high boundary
1648 ! icb is the level of the low-mid boundary
1649 !
1650 ! !OUTPUT PARAMETERS:
1651  real(8), intent(OUT) :: taubeam(nlevs,4) ! Optical Depth for Beam Radiation
1652  real(8), intent(OUT) :: taudiff(nlevs,4) ! Optical Depth for Diffuse Radiation
1653  real(8), intent(OUT) :: asycl(nlevs ) ! Cloud Asymmetry Factor
1654 ! !DESCRIPTION:
1655 ! Compute in-cloud or grid mean optical depths for visible wavelengths
1656 ! In general will compute in-cloud - will do grid mean when called
1657 ! for diagnostic use only. ict flag will indicate which to do.
1658 ! Slots for reff, hydrometeors, taubeam, taudiff, and asycl are as follows:
1659 ! 1 Cloud Ice
1660 ! 2 Cloud Liquid
1661 ! 3 Falling Liquid (Rain)
1662 ! 4 Falling Ice (Snow)
1663 !
1664 ! In the below calculations, the constants used in the tau calculation are in
1665 ! m$^2$ g$^{-1}$ and m$^2$ g$^{-1}$ $\mu$m. Thus, we must convert the kg contained in the
1666 ! pressure (Pa = kg m$^{-1}$ s$^{-2}$) to grams.
1667 !
1668 ! !REVISION HISTORY:
1669 ! 2011.10.27 Molod moved to Radiation_Shared and revised arg list, units
1670 ! 2011.11.16 MAT: Generalized to a call that is per-column
1671 !
1672 !EOP
1673 !------------------------------------------------------------------------------
1674 !BOC
1675 
1676  integer :: k,in,im,it,ia,kk
1677  real(8) :: fm,ft,fa,xai,tauc,asyclt
1678  real(8) :: cc(3)
1679  real(8) :: taucld1,taucld2,taucld3,taucld4
1680  real(8) :: g1,g2,g3,g4
1681 
1682  real(8) :: reff_snow
1683 
1684  integer, parameter :: nm=11,nt=9,na=11
1685  real(8), parameter :: dm=0.1,dt=0.30103,da=0.1,t1=-0.9031
1686 
1687  real(8), intent(in) :: aig_uv(3), awg_uv(3), arg_uv(3)
1688  real(8), intent(in) :: aib_uv, awb_uv(2), arb_uv(2)
1689  real(8), intent(in) :: aib_nir, awb_nir(3,2), arb_nir(3,2)
1690  real(8), intent(in) :: aia_nir(3,3), awa_nir(3,3), ara_nir(3,3)
1691  real(8), intent(in) :: aig_nir(3,3), awg_nir(3,3), arg_nir(3,3)
1692  real(8), intent(in) :: caib(11,9,11), caif(9,11)
1693  real(8), intent(in) :: cons_grav
1694 
1695  taubeam = 0.0
1696  taudiff = 0.0
1697 
1698  if (ict.ne.0) then
1699 
1700 !-----scale cloud optical thickness in each layer from taucld (with
1701 ! cloud amount fcld) to taubeam and taudiff (with cloud amount cc).
1702 ! taubeam is the scaled optical thickness for beam radiation and
1703 ! taudiff is for diffuse radiation (see section 7).
1704 
1705 !-----clouds within each of the high, middle, and low clouds are
1706 ! assumed to be maximally overlapped, and the cloud cover (cc)
1707 ! for a group (high, middle, or low) is the maximum cloud cover
1708 ! of all the layers within a group
1709 
1710  cc = 0.0
1711 
1712  do k = 1, ict-1
1713  cc(1)=max(cc(1),fcld(k))
1714  end do
1715  do k = ict, icb-1
1716  cc(2)=max(cc(2),fcld(k))
1717  end do
1718  do k = icb, nlevs
1719  cc(3)=max(cc(3),fcld(k))
1720  end do
1721 
1722  end if
1723 
1724 !-----Compute cloud optical thickness. Eqs. (4.6) and (4.10)
1725 ! Note: the cloud optical properties are assumed to be independent
1726 ! of spectral bands in the UV and PAR regions.
1727 ! taucld1 is the optical thickness for ice particles
1728 ! taucld2 is the optical thickness for liquid particles
1729 ! taucld3 is the optical thickness for rain drops
1730 ! taucld4 is the optical thickness for snow
1731 
1732  do k = 1, nlevs
1733 
1734  if (reff(k,1) <= 0.) then
1735  taucld1=0.
1736  else
1737  taucld1=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,1))*aib_uv/reff(k,1)
1738  end if
1739 
1740  if (reff(k,2) <= 0.) then
1741  taucld2=0.
1742  else
1743  taucld2=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,2))*(awb_uv(1)+awb_uv(2)/reff(k,2))
1744  end if
1745 
1746  taucld3=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,3))*arb_uv(1)
1747 
1748 !-----In the IR optical thickness calculation (getirtau.code), it was
1749 ! found that using the table of coefficients tabulated for suspended
1750 ! cloud ice particles (aib_ir) for falling snow lead to unphysical
1751 ! (negative) values of cloud optical thickness for effective radii
1752 ! greater than 113 microns. By restricting the effective radius of
1753 ! snow to 112 microns, we prevent unphysical optical thicknesses.
1754 ! For consistency's sake, we limit snow effective radius similarly here.
1755 
1756  reff_snow = min(reff(k,4),112.0)
1757 
1758  if (reff_snow <= 0.) then
1759  taucld4=0.
1760  else
1761  taucld4=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,4))*aib_uv/reff_snow
1762  endif
1763 
1764  if ( ict .ne. 0 ) then
1765 
1766 !-----scale cloud optical thickness in each layer from taucld (with
1767 ! cloud amount fcld) to taubeam and taudiff (with cloud amount cc).
1768 ! taubeam is the scaled optical thickness for beam radiation and
1769 ! taudiff is for diffuse radiation (see section 7).
1770 
1771 !-----clouds within each of the high, middle, and low clouds are
1772 ! assumed to be maximally overlapped, and the cloud cover (cc)
1773 ! for a group (high, middle, or low) is the maximum cloud cover
1774 ! of all the layers within a group
1775 
1776  if (k.lt.ict) then
1777  kk=1
1778  else if (k.ge.ict .and. k.lt.icb) then
1779  kk=2
1780  else
1781  kk=3
1782  end if
1783 
1784  tauc=taucld1+taucld2+taucld3+taucld4
1785 
1786  if (tauc.gt.0.02 .and. fcld(k).gt.0.01) then
1787 
1788 !-----normalize cloud cover following Eq. (7.8)
1789 
1790  fa=fcld(k)/cc(kk)
1791 
1792 !-----table look-up
1793 
1794  tauc=min(tauc,32.)
1795 
1796  fm=cosz/dm
1797  ft=(log10(tauc)-t1)/dt
1798  fa=fa/da
1799 
1800  im=int(fm+1.5)
1801  it=int(ft+1.5)
1802  ia=int(fa+1.5)
1803 
1804  im=max(im,2)
1805  it=max(it,2)
1806  ia=max(ia,2)
1807 
1808  im=min(im,nm-1)
1809  it=min(it,nt-1)
1810  ia=min(ia,na-1)
1811 
1812  fm=fm-real(im-1)
1813  ft=ft-real(it-1)
1814  fa=fa-real(ia-1)
1815 
1816 !-----scale cloud optical thickness for beam radiation following
1817 ! Eq. (7.3).
1818 ! the scaling factor, xai, is a function of the solar zenith
1819 ! angle, optical thickness, and cloud cover.
1820 
1821  xai= (-caib(im-1,it,ia)*(1.-fm)+&
1822  caib(im+1,it,ia)*(1.+fm))*fm*.5+caib(im,it,ia)*(1.-fm*fm)
1823 
1824  xai=xai+(-caib(im,it-1,ia)*(1.-ft)+&
1825  caib(im,it+1,ia)*(1.+ft))*ft*.5+caib(im,it,ia)*(1.-ft*ft)
1826 
1827  xai=xai+(-caib(im,it,ia-1)*(1.-fa)+&
1828  caib(im,it,ia+1)*(1.+fa))*fa*.5+caib(im,it,ia)*(1.-fa*fa)
1829 
1830  xai=xai-2.*caib(im,it,ia)
1831 
1832  xai=max(xai,0.0)
1833  xai=min(xai,1.0)
1834 
1835  taubeam(k,1)=taucld1*xai
1836  taubeam(k,2)=taucld2*xai
1837  taubeam(k,3)=taucld3*xai
1838  taubeam(k,4)=taucld4*xai
1839 
1840 !-----scale cloud optical thickness for diffuse radiation following
1841 ! Eq. (7.4).
1842 ! the scaling factor, xai, is a function of the cloud optical
1843 ! thickness and cover but not the solar zenith angle.
1844 
1845  xai= (-caif(it-1,ia)*(1.-ft)+&
1846  caif(it+1,ia)*(1.+ft))*ft*.5+caif(it,ia)*(1.-ft*ft)
1847 
1848  xai=xai+(-caif(it,ia-1)*(1.-fa)+&
1849  caif(it,ia+1)*(1.+fa))*fa*.5+caif(it,ia)*(1.-fa*fa)
1850 
1851  xai=xai-caif(it,ia)
1852 
1853  xai=max(xai,0.0)
1854  xai=min(xai,1.0)
1855 
1856  taudiff(k,1)=taucld1*xai
1857  taudiff(k,2)=taucld2*xai
1858  taudiff(k,3)=taucld3*xai
1859  taudiff(k,4)=taucld4*xai
1860  end if
1861  else
1862  ! Overlap calculation scaling not needed
1863  taubeam(k,1)=taucld1
1864  taubeam(k,2)=taucld2
1865  taubeam(k,3)=taucld3
1866  taubeam(k,4)=taucld4
1867 
1868  taudiff(k,1)=taucld1
1869  taudiff(k,2)=taucld2
1870  taudiff(k,3)=taucld3
1871  taudiff(k,4)=taucld4
1872  end if
1873 
1874 !-----cloud asymmetry factor for a mixture of liquid and ice particles.
1875 ! unit of reff is micrometers. Eqs. (4.8) and (6.4)
1876 
1877  asyclt=1.0
1878  tauc=taucld1+taucld2+taucld3+taucld4
1879 
1880  if (tauc.gt.0.02 .and. fcld(k).gt.0.01) then
1881  g1=(aig_uv(1)+(aig_uv(2)+aig_uv(3)*reff(k,1))*reff(k,1))*taucld1
1882  g2=(awg_uv(1)+(awg_uv(2)+awg_uv(3)*reff(k,2))*reff(k,2))*taucld2
1883  g3= arg_uv(1) *taucld3
1884  g4=(aig_uv(1)+(aig_uv(2)+aig_uv(3)*reff_snow)*reff_snow)*taucld4
1885  asyclt=(g1+g2+g3+g4)/tauc
1886  end if
1887 
1888  asycl(k)=asyclt
1889 
1890  end do
1891 
1892  return
1893 
1894 !EOC
1895  end subroutine getvistau1
1896 
1897 
1898 
1899  subroutine getnirtau1(ib,nlevs,cosz,dp,fcld,reff,hydromets,ict,icb, &
1900  taubeam,taudiff,asycl,ssacl, &
1901  aig_uv, awg_uv, arg_uv, &
1902  aib_uv, awb_uv, arb_uv, &
1903  aib_nir, awb_nir, arb_nir, &
1904  aia_nir, awa_nir, ara_nir, &
1905  aig_nir, awg_nir, arg_nir, &
1906  caib, caif, &
1907  CONS_GRAV )
1909 
1910  implicit none
1911 
1912 ! !INPUT PARAMETERS:
1913  integer, intent(IN ) :: ib ! Band number
1914  integer, intent(IN ) :: nlevs ! Number of levels
1915  real(8), intent(IN ) :: cosz ! Cosine of solar zenith angle
1916  real(8), intent(IN ) :: dp(nlevs) ! Delta pressure in Pa
1917  real(8), intent(IN ) :: fcld(nlevs) ! Cloud fraction (used sometimes)
1918  real(8), intent(IN ) :: reff(nlevs,4) ! Effective radius (microns)
1919  real(8), intent(IN ) :: hydromets(nlevs,4) ! Hydrometeors (kg/kg)
1920  integer, intent(IN ) :: ict, icb ! Flags for various uses
1921 
1922  real(8), intent(in) :: aig_uv(3), awg_uv(3), arg_uv(3)
1923  real(8), intent(in) :: aib_uv, awb_uv(2), arb_uv(2)
1924  real(8), intent(in) :: aib_nir, awb_nir(3,2), arb_nir(3,2)
1925  real(8), intent(in) :: aia_nir(3,3), awa_nir(3,3), ara_nir(3,3)
1926  real(8), intent(in) :: aig_nir(3,3), awg_nir(3,3), arg_nir(3,3)
1927  real(8), intent(in) :: caib(11,9,11), caif(9,11)
1928  real(8), intent(in) :: cons_grav
1929 
1930 ! !OUTPUT PARAMETERS:
1931  real(8), intent(OUT) :: taubeam(nlevs,4) ! Optical depth for beam radiation
1932  real(8), intent(OUT) :: taudiff(nlevs,4) ! Optical depth for diffuse radiation
1933  real(8), intent(OUT) :: ssacl(nlevs ) ! Cloud single scattering albedo
1934  real(8), intent(OUT) :: asycl(nlevs ) ! Cloud asymmetry factor
1935 
1936  integer :: k,in,im,it,ia,kk
1937  real(8) :: fm,ft,fa,xai,tauc,asyclt,ssaclt
1938  real(8) :: cc(3)
1939  real(8) :: taucld1,taucld2,taucld3,taucld4
1940  real(8) :: g1,g2,g3,g4
1941  real(8) :: w1,w2,w3,w4
1942 
1943  real(8) :: reff_snow
1944 
1945  integer, parameter :: nm=11,nt=9,na=11
1946  real(8), parameter :: dm=0.1,dt=0.30103,da=0.1,t1=-0.9031
1947 
1948  taubeam = 0.0
1949  taudiff = 0.0
1950 
1951  if (ict.ne.0) then
1952 
1953 !-----scale cloud optical thickness in each layer from taucld (with
1954 ! cloud amount fcld) to taubeam and taudiff (with cloud amount cc).
1955 ! taubeam is the scaled optical thickness for beam radiation and
1956 ! taudiff is for diffuse radiation (see section 7).
1957 
1958 !-----clouds within each of the high, middle, and low clouds are
1959 ! assumed to be maximally overlapped, and the cloud cover (cc)
1960 ! for a group (high, middle, or low) is the maximum cloud cover
1961 ! of all the layers within a group
1962 
1963  cc = 0.0
1964 
1965  do k = 1, ict-1
1966  cc(1)=max(cc(1),fcld(k))
1967  end do
1968  do k = ict, icb-1
1969  cc(2)=max(cc(2),fcld(k))
1970  end do
1971  do k = icb, nlevs
1972  cc(3)=max(cc(3),fcld(k))
1973  end do
1974 
1975  end if
1976 
1977 !-----Compute cloud optical thickness. Eqs. (4.6) and (4.10)
1978 ! taucld1 is the optical thickness for ice particles
1979 ! taucld2 is the optical thickness for liquid particles
1980 ! taucld3 is the optical thickness for rain drops
1981 ! taucld4 is the optical thickness for snow
1982 
1983  do k = 1, nlevs
1984 
1985  if (reff(k,1) <= 0.) then
1986  taucld1=0.
1987  else
1988  taucld1=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,1))*aib_nir/reff(k,1)
1989  end if
1990 
1991  if (reff(k,2) <= 0.) then
1992  taucld2=0.
1993  else
1994  taucld2=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,2))*(awb_nir(ib,1)+awb_nir(ib,2)/reff(k,2))
1995  end if
1996 
1997  taucld3=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,3))*arb_nir(ib,1)
1998 
1999 !-----In the IR optical thickness calculation (getirtau.code), it was
2000 ! found that using the table of coefficients tabulated for suspended
2001 ! cloud ice particles (aib_ir) for falling snow lead to unphysical
2002 ! (negative) values of cloud optical thickness for effective radii
2003 ! greater than 113 microns. By restricting the effective radius of
2004 ! snow to 112 microns, we prevent unphysical optical thicknesses.
2005 ! For consistency's sake, we limit snow effective radius similarly here.
2006 
2007  reff_snow = min(reff(k,4),112.0)
2008 
2009  if (reff_snow <= 0.) then
2010  taucld4=0.
2011  else
2012  taucld4=(((dp(k)*1.0e3)/cons_grav)*hydromets(k,4))*aib_nir/reff_snow
2013  endif
2014 
2015  if ( ict .ne. 0 ) then
2016 
2017 !-----scale cloud optical thickness in each layer from taucld (with
2018 ! cloud amount fcld) to taubeam and taudiff (with cloud amount cc).
2019 ! taubeam is the scaled optical thickness for beam radiation and
2020 ! taudiff is for diffuse radiation (see section 7).
2021 
2022 !-----clouds within each of the high, middle, and low clouds are
2023 ! assumed to be maximally overlapped, and the cloud cover (cc)
2024 ! for a group (high, middle, or low) is the maximum cloud cover
2025 ! of all the layers within a group
2026 
2027  if (k.lt.ict) then
2028  kk=1
2029  else if (k.ge.ict .and. k.lt.icb) then
2030  kk=2
2031  else
2032  kk=3
2033  end if
2034 
2035  tauc=taucld1+taucld2+taucld3+taucld4
2036 
2037  if (tauc.gt.0.02 .and. fcld(k).gt.0.01) then
2038 
2039 !-----normalize cloud cover following Eq. (7.8)
2040  if (cc(kk).ne.0.0) then
2041  fa=fcld(k)/cc(kk)
2042  else
2043  fa=0.0
2044  end if
2045 
2046 !-----table look-up
2047 
2048  tauc=min(tauc,32.)
2049 
2050  fm=cosz/dm
2051  ft=(log10(tauc)-t1)/dt
2052  fa=fa/da
2053 
2054  im=int(fm+1.5)
2055  it=int(ft+1.5)
2056  ia=int(fa+1.5)
2057 
2058  im=max(im,2)
2059  it=max(it,2)
2060  ia=max(ia,2)
2061 
2062  im=min(im,nm-1)
2063  it=min(it,nt-1)
2064  ia=min(ia,na-1)
2065 
2066  fm=fm-real(im-1)
2067  ft=ft-real(it-1)
2068  fa=fa-real(ia-1)
2069 
2070 !-----scale cloud optical thickness for beam radiation following
2071 ! Eq. (7.3).
2072 ! the scaling factor, xai, is a function of the solar zenith
2073 ! angle, optical thickness, and cloud cover.
2074 
2075  xai= (-caib(im-1,it,ia)*(1.-fm)+&
2076  caib(im+1,it,ia)*(1.+fm))*fm*.5+caib(im,it,ia)*(1.-fm*fm)
2077 
2078  xai=xai+(-caib(im,it-1,ia)*(1.-ft)+&
2079  caib(im,it+1,ia)*(1.+ft))*ft*.5+caib(im,it,ia)*(1.-ft*ft)
2080 
2081  xai=xai+(-caib(im,it,ia-1)*(1.-fa)+&
2082  caib(im,it,ia+1)*(1.+fa))*fa*.5+caib(im,it,ia)*(1.-fa*fa)
2083 
2084  xai=xai-2.*caib(im,it,ia)
2085 
2086  xai=max(xai,0.0)
2087  xai=min(xai,1.0)
2088 
2089  taubeam(k,1)=taucld1*xai
2090  taubeam(k,2)=taucld2*xai
2091  taubeam(k,3)=taucld3*xai
2092  taubeam(k,4)=taucld4*xai
2093 
2094 !-----scale cloud optical thickness for diffuse radiation following
2095 ! Eq. (7.4).
2096 ! the scaling factor, xai, is a function of the cloud optical
2097 ! thickness and cover but not the solar zenith angle.
2098 
2099  xai= (-caif(it-1,ia)*(1.-ft)+&
2100  caif(it+1,ia)*(1.+ft))*ft*.5+caif(it,ia)*(1.-ft*ft)
2101 
2102  xai=xai+(-caif(it,ia-1)*(1.-fa)+&
2103  caif(it,ia+1)*(1.+fa))*fa*.5+caif(it,ia)*(1.-fa*fa)
2104 
2105  xai=xai-caif(it,ia)
2106 
2107  xai=max(xai,0.0)
2108  xai=min(xai,1.0)
2109 
2110  taudiff(k,1)=taucld1*xai
2111  taudiff(k,2)=taucld2*xai
2112  taudiff(k,3)=taucld3*xai
2113  taudiff(k,4)=taucld4*xai
2114  end if
2115  else
2116  ! Overlap calculation scaling not needed
2117  taubeam(k,1)=taucld1
2118  taubeam(k,2)=taucld2
2119  taubeam(k,3)=taucld3
2120  taubeam(k,4)=taucld4
2121 
2122  taudiff(k,1)=taucld1
2123  taudiff(k,2)=taucld2
2124  taudiff(k,3)=taucld3
2125  taudiff(k,4)=taucld4
2126  end if
2127 
2128 !-----compute cloud single scattering albedo and asymmetry factor
2129 ! for a mixture of ice and liquid particles.
2130 ! Eqs.(4.6)-(4.8), (6.2)-(6.4)
2131 
2132  ssaclt=0.99999
2133  asyclt=1.0
2134  tauc=taucld1+taucld2+taucld3+taucld4
2135 
2136  if (tauc.gt.0.02 .and. fcld(k).gt.0.01) then
2137 
2138  w1=(1.-(aia_nir(ib,1)+(aia_nir(ib,2)+aia_nir(ib,3)*reff(k,1))*reff(k,1)))*taucld1
2139  w2=(1.-(awa_nir(ib,1)+(awa_nir(ib,2)+awa_nir(ib,3)*reff(k,2))*reff(k,2)))*taucld2
2140  w3=(1.- ara_nir(ib,1)) *taucld3
2141  w4=(1.-(aia_nir(ib,1)+(aia_nir(ib,2)+aia_nir(ib,3)*reff_snow)*reff_snow))*taucld4
2142  ssaclt=(w1+w2+w3+w4)/tauc
2143 
2144  g1=(aig_nir(ib,1)+(aig_nir(ib,2)+aig_nir(ib,3)*reff(k,1))*reff(k,1))*w1
2145  g2=(awg_nir(ib,1)+(awg_nir(ib,2)+awg_nir(ib,3)*reff(k,2))*reff(k,2))*w2
2146  g3= arg_nir(ib,1) *w3
2147 
2148  g4=(aig_nir(ib,1)+(aig_nir(ib,2)+aig_nir(ib,3)*reff(k,4))*reff(k,4))*w4
2149 
2150  if ((w1+w2+w3+w4).ne.0.0) then
2151  asyclt=(g1+g2+g3+g4)/(w1+w2+w3+w4)
2152  end if
2153 
2154 
2155  end if
2156 
2157  ssacl(k)=ssaclt
2158  asycl(k)=asyclt
2159 
2160  end do
2161 
2162  return
2163 
2164  end subroutine getnirtau1
2165 
2166 
2167 end module soradmod
subroutine, public deledd(tau1, ssc1, g01, cza1, rr1, tt1, td1)
Definition: sorad.F90:1495
real(fp), parameter, public zero
real(fp), parameter, public four
real(fp), parameter, public three
subroutine, public getnirtau1(ib, nlevs, cosz, dp, fcld, reff, hydromets, ict, icb, taubeam, taudiff, asycl, ssacl, aig_uv, awg_uv, arg_uv, aib_uv, awb_uv, arb_uv, aib_nir, awb_nir, arb_nir, aia_nir, awa_nir, ara_nir, aig_nir, awg_nir, arg_nir, caib, caif, CONS_GRAV)
Definition: sorad.F90:1908
subroutine, public getvistau1(nlevs, cosz, dp, fcld, reff, hydromets, ict, icb, taubeam, taudiff, asycl, aig_uv, awg_uv, arg_uv, aib_uv, awb_uv, arb_uv, aib_nir, awb_nir, arb_nir, aia_nir, awa_nir, ara_nir, aig_nir, awg_nir, arg_nir, caib, caif, CONS_GRAV)
Definition: sorad.F90:1631
real(kind=kind_real), parameter u1
real(fp), parameter, public one
real(fp), parameter, public two
subroutine, public sorad(m, np, nb, cosz_dev, pl_dev, ta_dev, wa_dev, oa_dev, co2, cwc_dev, fcld_dev, ict, icb, reff_dev, hk_uv, hk_ir, taua_dev, ssaa_dev, asya_dev, rsuvbm_dev, rsuvdf_dev, rsirbm_dev, rsirdf_dev, flx_dev, CONS_GRAV, wk_uv, zk_uv, ry_uv, xk_ir, ry_ir, cah, coa, aig_uv, awg_uv, arg_uv, aib_uv, awb_uv, arb_uv, aib_nir, awb_nir, arb_nir, aia_nir, awa_nir, ara_nir, aig_nir, awg_nir, arg_nir, caib, caif)
Definition: sorad.F90:46
#define max(a, b)
Definition: mosaic_util.h:33
#define min(a, b)
Definition: mosaic_util.h:32