FV3 Bundle
cloud_tl.F90
Go to the documentation of this file.
1 MODULE cloud_tl
2 
3 USE cloud, ONLY: pdf_width
4 
5 IMPLICIT NONE
6 
7 PRIVATE
9 
10 CONTAINS
11 ! Generated by TAPENADE (INRIA, Tropics team)
12 ! Tapenade 3.9 (r5096) - 24 Feb 2014 16:53
13 !
14 ! Differentiation of cloud_driver in forward (tangent) mode:
15 ! variations of useful results: th qi_con q cf_ls cf_con ql_ls
16 ! ql_con qi_ls
17 ! with respect to varying inputs: th qi_con cnv_prc3 q cnv_dqldt
18 ! cf_ls cnv_updf cf_con cnv_mfd ql_ls ql_con qi_ls
19 ! RW status of diff variables: th:in-out qi_con:in-out cnv_prc3:in
20 ! q:in-out cnv_dqldt:in cf_ls:in-out cnv_updf:in
21 ! cf_con:in-out cnv_mfd:in ql_ls:in-out ql_con:in-out
22 ! qi_ls:in-out
23 SUBROUTINE cloud_driver_d(dt, im, jm, lm, th, thd, q, qd, ple, cnv_dqldt&
24 & , cnv_dqldtd, cnv_mfd, cnv_mfdd, cnv_prc3, cnv_prc3d, cnv_updf, &
25 & cnv_updfd, qi_ls, qi_lsd, ql_ls, ql_lsd, qi_con, qi_cond, ql_con, &
26 & ql_cond, cf_ls, cf_lsd, cf_con, cf_cond, frland, physparams, estblx, &
27 & khu, khl, cons_runiv, cons_kappa, cons_airmw, cons_h2omw, cons_grav, &
28 & cons_alhl, cons_alhf, cons_pi, cons_rgas, cons_cp, cons_vireps, &
29 & cons_alhs, cons_tice, cons_rvap, cons_p00, do_moist_physics)
30  IMPLICIT NONE
31 !INPUTS
32  INTEGER, INTENT(IN) :: im, jm, lm, do_moist_physics
33  REAL*8, INTENT(IN) :: dt, frland(im, jm), physparams(:)
34  REAL*8, DIMENSION(im, jm, lm), INTENT(IN) :: cnv_dqldt, cnv_mfd, &
35 & cnv_updf, cnv_prc3
36  REAL*8, DIMENSION(im, jm, lm), INTENT(IN) :: cnv_dqldtd, cnv_mfdd, &
37 & cnv_updfd, cnv_prc3d
38  REAL*8, INTENT(IN) :: estblx(:)
39  REAL*8, DIMENSION(im, jm, 0:lm), INTENT(IN) :: ple
40  INTEGER, DIMENSION(im, jm), INTENT(IN) :: khu, khl
41 !MAPL_CONSTANTS REDEFINED FOR USE IN AUTODIFF TOOL
42  REAL*8, INTENT(IN) :: cons_runiv, cons_kappa, cons_airmw
43  REAL*8, INTENT(IN) :: cons_h2omw, cons_grav, cons_alhl
44  REAL*8, INTENT(IN) :: cons_alhf, cons_pi, cons_rgas
45  REAL*8, INTENT(IN) :: cons_cp, cons_vireps, cons_alhs
46  REAL*8, INTENT(IN) :: cons_tice, cons_rvap, cons_p00
47 !PROGNOSTICS
48  REAL*8, DIMENSION(im, jm, lm), INTENT(INOUT) :: th, q
49  REAL*8, DIMENSION(im, jm, lm), INTENT(INOUT) :: thd, qd
50  REAL*8, DIMENSION(im, jm, lm), INTENT(INOUT) :: qi_ls, ql_ls, qi_con, &
51 & ql_con, cf_con, cf_ls
52  REAL*8, DIMENSION(im, jm, lm), INTENT(INOUT) :: qi_lsd, ql_lsd, &
53 & qi_cond, ql_cond, cf_cond, cf_lsd
54 !OUTPUTS (DIAGNOSTICS)
55 !LOCALS
56  INTEGER :: i, j, k, l, ktop
57  REAL*8, DIMENSION(im, jm, lm) :: ph, pih, mass, imass, t, dzet, qddf3&
58 & , rh, dp, dm
59  REAL*8, DIMENSION(im, jm, lm) :: td, dzetd, qddf3d
60  REAL*8, DIMENSION(im, jm, lm + 1) :: zet
61  REAL*8, DIMENSION(im, jm, lm+1) :: zetd
62  REAL*8, DIMENSION(im, jm, 0:lm) :: p, pi
63  REAL*8, DIMENSION(im, jm, lm) :: qs, dqsdt, dqs
64  REAL*8, DIMENSION(im, jm, lm) :: qsd, dqsdtd, dqsd
65  REAL*8, DIMENSION(im, jm) :: vmip
66  REAL*8, DIMENSION(im, jm) :: vmipd
67 !Precip amounts and fall rate
68  REAL*8 :: cf_tot
69  REAL*8 :: cf_totd
70  REAL*8 :: alpha, alhx3, rhcrit
71  REAL*8 :: alhx3d
72 !Microphyiscal constants
73  REAL*8 :: aa, bb
74  REAL*8 :: aad, bbd
75  REAL*8, PARAMETER :: pi_0=4.*atan(1.)
76 !Density of liquid water in kg/m^3
77  REAL*8, PARAMETER :: rho_w=1.0e3
78  REAL*8 :: t_ice_max
79 !PHYSPARAMS constants
80  REAL*8 :: cnv_beta, anv_beta, ls_beta, rh00, c_00, lwcrit, c_acc, &
81 & c_ev_r, c_ev_s, cldvol2frc
82  REAL*8 :: rhsup_ice, shr_evap_fac, min_cld_water, cld_evp_eff, &
83 & ls_sdqv2, ls_sdqv3, ls_sdqvt1
84  REAL*8 :: anv_sdqv2, anv_sdqv3, anv_sdqvt1, anv_to_ls, n_warm, n_ice, &
85 & n_anvil, n_pbl
86  REAL*8 :: anv_icefall_c, ls_icefall_c, revap_off_p, cnvenvfc, wrhodep&
87 & , t_ice_all, cnviceparam
88  REAL*8 :: cnvddrfc, anvddrfc, lsddrfc, minrhcrit, maxrhcrit, &
89 & turnrhcrit, maxrhcritland
90  REAL*8 :: min_rl, min_ri, max_rl, max_ri, ri_anv
91  INTEGER :: nsmax, disable_rad, icefrpwr, tanhrhcrit, fr_ls_wat, &
92 & fr_ls_ice, fr_an_wat, fr_an_ice, pdfflag
93  REAL*8 :: lsenvfc, anvenvfc
94  REAL*8 :: qrn_cu, qsn_cu, qrn_an, qsn_an, qrn_ls, qsn_ls, qrn_cu_1d
95  REAL*8 :: qsn_cud, qrn_and, qsn_and, qrn_lsd, qsn_lsd, qrn_cu_1dd
96  REAL*8 :: qt_tmpi_1, qt_tmpi_2, qlt_tmp, qit_tmp
97  REAL*8 :: qt_tmpi_1d, qt_tmpi_2d, qlt_tmpd, qit_tmpd
98  REAL*8 :: prn_above_cu_new, prn_above_an_new, prn_above_ls_new
99  REAL*8 :: prn_above_cu_newd, prn_above_an_newd, prn_above_ls_newd
100  REAL*8 :: prn_above_cu_old, prn_above_an_old, prn_above_ls_old
101  REAL*8 :: prn_above_cu_oldd, prn_above_an_oldd, prn_above_ls_oldd
102  REAL*8 :: psn_above_cu_new, psn_above_an_new, psn_above_ls_new
103  REAL*8 :: psn_above_cu_newd, psn_above_an_newd, psn_above_ls_newd
104  REAL*8 :: psn_above_cu_old, psn_above_an_old, psn_above_ls_old
105  REAL*8 :: psn_above_cu_oldd, psn_above_an_oldd, psn_above_ls_oldd
106  REAL*8 :: evap_dd_cu_above_new, evap_dd_an_above_new, &
107 & evap_dd_ls_above_new
108  REAL*8 :: evap_dd_cu_above_newd, evap_dd_an_above_newd, &
109 & evap_dd_ls_above_newd
110  REAL*8 :: evap_dd_cu_above_old, evap_dd_an_above_old, &
111 & evap_dd_ls_above_old
112  REAL*8 :: evap_dd_cu_above_oldd, evap_dd_an_above_oldd, &
113 & evap_dd_ls_above_oldd
114  REAL*8 :: subl_dd_cu_above_new, subl_dd_an_above_new, &
115 & subl_dd_ls_above_new
116  REAL*8 :: subl_dd_cu_above_newd, subl_dd_an_above_newd, &
117 & subl_dd_ls_above_newd
118  REAL*8 :: subl_dd_cu_above_old, subl_dd_an_above_old, &
119 & subl_dd_ls_above_old
120  REAL*8 :: subl_dd_cu_above_oldd, subl_dd_an_above_oldd, &
121 & subl_dd_ls_above_oldd
122  REAL*8 :: area_ls_prc1, area_upd_prc1, area_anv_prc1
123  REAL*8 :: area_ls_prc1d, area_upd_prc1d, area_anv_prc1d
124  REAL*8 :: tot_prec_upd, tot_prec_anv, tot_prec_ls, area_upd_prc, &
125 & area_anv_prc, area_ls_prc
126  REAL*8 :: tot_prec_updd, tot_prec_anvd, tot_prec_lsd, area_upd_prcd, &
127 & area_anv_prcd, area_ls_prcd
128  REAL*8 :: qtmp2
129  REAL*8 :: rhexcess, tpw, negtpw
130  REAL*8 :: tpwd, negtpwd
131  INTEGER :: cloud_pertmod
132  INTRINSIC atan
133  INTRINSIC int
134  INTRINSIC sum
135  INTRINSIC max
136  REAL*8, DIMENSION(im, jm, 0:lm) :: pwx1
137  REAL*8 :: pwy1
138  REAL*8, DIMENSION(im, jm, lm) :: pwx10
139 
140  !LS_CLOUD FILTERING
141  integer :: ii
142  real(8) :: xx(8)
143  real(8) :: ttraj, qtraj, qi_lstraj, qi_contraj, ql_lstraj, ql_contraj, cf_lstraj, cf_contraj, phtraj
144  real(8) :: tpert, qpert, qi_lspert, qi_conpert, ql_lspert, ql_conpert, cf_lspert, cf_conpert
145  real(8) :: jacobian(8,8), a(8,8)
146 
147  !Eigenvalue computation
148  integer, parameter :: n1 = 8
149  integer, parameter :: lda = 8
150  REAL(8) :: wr(n1), wi(n1)
151  INTEGER, PARAMETER :: ldvl = n1 !Left vecotrs
152  REAL(8) :: vl(ldvl,n1)
153  INTEGER, PARAMETER :: ldvr = n1 !Right vectors
154  REAL(8) :: vr(ldvr,n1)
155  INTEGER :: info, lwork
156  INTEGER, PARAMETER :: lwmax = 10000
157  REAL(8) :: work(lwmax)
158  EXTERNAL :: dgeev
159  REAL*8 :: maxeval
160 
161  !Total Filtering
162  real(8) :: totfilt_t, totfilt_ql, totfilt_qi
163  real(8) :: t_p_preall, ql_ls_p_preall, ql_con_p_preall, qi_ls_p_preall, qi_con_p_preall
164 
165  !Sink Filtering
166  real(8) :: sinkfilt_ql, sinkfilt_qi, sinkfilt_cf
167  real(8) :: t_p_presink, q_p_presink
168  real(8) :: ql_ls_p_presink, ql_con_p_presink
169  real(8) :: qi_ls_p_presink, qi_con_p_presink
170  !real(8) :: cf_con_p_presink
171 
172 !Highest level of calculations
173  ktop = 30
174 !Get Constants from CLOUDPARAMS
175 ! Area factor for convective rain showers (non-dim)
176  cnv_beta = physparams(1)
177 ! Area factor for anvil rain showers (non-dim)
178  anv_beta = physparams(2)
179 ! Area factor for Large Scale rain showers (non-dim)
180  ls_beta = physparams(3)
181 ! Critical relative humidity
182  rh00 = physparams(4)
183  c_00 = physparams(5)
184  lwcrit = physparams(6)
185  c_acc = physparams(7)
186  c_ev_r = physparams(8)
187  c_ev_s = physparams(56)
188  cldvol2frc = physparams(9)
189  rhsup_ice = physparams(10)
190  shr_evap_fac = physparams(11)
191  min_cld_water = physparams(12)
192  cld_evp_eff = physparams(13)
193  nsmax = int(physparams(14))
194  ls_sdqv2 = physparams(15)
195  ls_sdqv3 = physparams(16)
196  ls_sdqvt1 = physparams(17)
197  anv_sdqv2 = physparams(18)
198  anv_sdqv3 = physparams(19)
199  anv_sdqvt1 = physparams(20)
200  anv_to_ls = physparams(21)
201  n_warm = physparams(22)
202  n_ice = physparams(23)
203  n_anvil = physparams(24)
204  n_pbl = physparams(25)
205  disable_rad = int(physparams(26))
206  anv_icefall_c = physparams(28)
207  ls_icefall_c = physparams(29)
208  revap_off_p = physparams(30)
209  cnvenvfc = physparams(31)
210  wrhodep = physparams(32)
211  t_ice_all = physparams(33) + cons_tice
212  cnviceparam = physparams(34)
213  icefrpwr = int(physparams(35) + .001)
214  cnvddrfc = physparams(36)
215  anvddrfc = physparams(37)
216  lsddrfc = physparams(38)
217  tanhrhcrit = int(physparams(41))
218  minrhcrit = physparams(42)
219  maxrhcrit = physparams(43)
220  turnrhcrit = physparams(45)
221  maxrhcritland = physparams(46)
222  fr_ls_wat = int(physparams(47))
223  fr_ls_ice = int(physparams(48))
224  fr_an_wat = int(physparams(49))
225  fr_an_ice = int(physparams(50))
226  min_rl = physparams(51)
227  min_ri = physparams(52)
228  max_rl = physparams(53)
229  max_ri = physparams(54)
230  ri_anv = physparams(55)
231  pdfflag = int(physparams(57))
232  t_ice_max = cons_tice
233 !Initialize the saving of downdraft values.
234  prn_above_cu_new = 0.
235  prn_above_an_new = 0.
236  prn_above_ls_new = 0.
237  psn_above_cu_new = 0.
238  psn_above_an_new = 0.
239  psn_above_ls_new = 0.
240  evap_dd_cu_above_new = 0.
241  evap_dd_an_above_new = 0.
242  evap_dd_ls_above_new = 0.
243  subl_dd_cu_above_new = 0.
244  subl_dd_an_above_new = 0.
245  subl_dd_ls_above_new = 0.
246 !Convert to hPa and average pressure to temperature levels
247  p = ple*0.01
248  ph = 0.5*(p(:, :, 0:lm-1)+p(:, :, 1:lm))
249 !Calculate Exner Pressure at temperature levels
250  pwx1 = p/1000.
251  pwy1 = cons_rgas/cons_cp
252  pi = pwx1**pwy1
253  pwx10 = ph/1000.
254  pwy1 = cons_rgas/cons_cp
255  pih = pwx10**pwy1
256 !Calculate temperature
257  td = pih*thd
258  t = th*pih
259 !Compute QS and DQSDT
260  qsd = 0.0_8
261  dqsdtd = 0.0_8
262  CALL dqsat_bac_d(dqsdt, dqsdtd, qs, qsd, t, td, ph, im, jm, lm, estblx&
263 & , cons_h2omw, cons_airmw)
264 !Relative humidity
265  rh = q/qs
266 !Compute layer mass and 1/mass
267  mass = (p(:, :, 1:lm)-p(:, :, 0:lm-1))*100./cons_grav
268  imass = 1/mass
269 !Level thickness
270  dzetd(:, :, 1:lm) = (pi(:, :, 1:lm)-pi(:, :, 0:lm-1))*cons_cp*thd(:, :&
271 & , 1:lm)/cons_grav
272  dzet(:, :, 1:lm) = th(:, :, 1:lm)*(pi(:, :, 1:lm)-pi(:, :, 0:lm-1))*&
273 & cons_cp/cons_grav
274 !Level heights
275  zetd(:, :, lm+1) = 0.0_8
276  zet(:, :, lm+1) = 0.0
277  zetd = 0.0_8
278  DO k=lm,1,-1
279  zetd(:, :, k) = zetd(:, :, k+1) + dzetd(:, :, k)
280  zet(:, :, k) = zet(:, :, k+1) + dzet(:, :, k)
281  END DO
282  qddf3d = 0.0_8
283  WHERE (zet(:, :, 1:lm) .LT. 3000.)
284  qddf3d = -(mass*(zetd(:, :, 1:lm)*zet(:, :, 1:lm)+(zet(:, :, 1:lm)-&
285 & 3000.)*zetd(:, :, 1:lm)))
286  qddf3 = -((zet(:, :, 1:lm)-3000.)*zet(:, :, 1:lm)*mass)
287  ELSEWHERE
288  qddf3d = 0.0_8
289  qddf3 = 0.
290  END WHERE
291  vmipd = 0.0_8
292  DO i=1,im
293  DO j=1,jm
294  vmipd(i, j) = sum(qddf3d(i, j, :))
295  vmip(i, j) = sum(qddf3(i, j, :))
296  END DO
297  END DO
298  DO k=1,lm
299  qddf3d(:, :, k) = (qddf3d(:, :, k)*vmip-qddf3(:, :, k)*vmipd)/vmip**&
300 & 2
301  qddf3(:, :, k) = qddf3(:, :, k)/vmip
302  END DO
303 !Pressure and mass thickness for use in cleanup.
304  dp = ple(:, :, 1:lm) - ple(:, :, 0:lm-1)
305  dm = dp*(1./cons_grav)
306  prn_above_cu_newd = 0.0_8
307  psn_above_cu_newd = 0.0_8
308  evap_dd_an_above_newd = 0.0_8
309  area_upd_prcd = 0.0_8
310  prn_above_ls_newd = 0.0_8
311  evap_dd_ls_above_newd = 0.0_8
312  evap_dd_cu_above_newd = 0.0_8
313  psn_above_ls_newd = 0.0_8
314  tot_prec_lsd = 0.0_8
315  area_ls_prcd = 0.0_8
316  tot_prec_updd = 0.0_8
317  prn_above_an_newd = 0.0_8
318  area_anv_prcd = 0.0_8
319  psn_above_an_newd = 0.0_8
320  alhx3d = 0.0_8
321  subl_dd_an_above_newd = 0.0_8
322  tot_prec_anvd = 0.0_8
323  subl_dd_ls_above_newd = 0.0_8
324  subl_dd_cu_above_newd = 0.0_8
325 !Begin loop over all grid boxes.
326  DO i=1,im
327  DO j=1,jm
328  DO k=ktop,lm
329 
330  !Save the inputs to the scheme for filtering
331  t_p_preall = td(i, j, k)
332  ql_ls_p_preall = ql_lsd(i, j, k)
333  ql_con_p_preall = ql_cond(i, j, k)
334  qi_ls_p_preall = qi_lsd(i, j, k)
335  qi_con_p_preall = qi_cond(i, j, k)
336 
337  IF (k .EQ. ktop) THEN
338  tot_prec_upd = 0.
339  tot_prec_anv = 0.
340  tot_prec_ls = 0.
341  area_upd_prc = 0.
342  area_anv_prc = 0.
343  area_ls_prc = 0.
344  area_upd_prcd = 0.0_8
345  tot_prec_lsd = 0.0_8
346  area_ls_prcd = 0.0_8
347  tot_prec_updd = 0.0_8
348  area_anv_prcd = 0.0_8
349  tot_prec_anvd = 0.0_8
350  END IF
351 !Initialize precips, except QRN_CU which comes from RAS
352  qrn_ls = 0.
353  qrn_an = 0.
354  qrn_cu_1d = 0.
355  qsn_ls = 0.
356  qsn_an = 0.
357  qsn_cu = 0.
358 !Ras Rain
359  qrn_cu_1dd = cnv_prc3d(i, j, k)
360  qrn_cu_1d = cnv_prc3(i, j, k)
361 !Tidy up where fractions or cloud is too low
362  CALL cloud_tidy_d(q(i, j, k), qd(i, j, k), t(i, j, k), td(i, j, &
363 & k), ql_ls(i, j, k), ql_lsd(i, j, k), qi_ls(i, j, k)&
364 & , qi_lsd(i, j, k), cf_ls(i, j, k), cf_lsd(i, j, k), &
365 & ql_con(i, j, k), ql_cond(i, j, k), qi_con(i, j, k), &
366 & qi_cond(i, j, k), cf_con(i, j, k), cf_cond(i, j, k)&
367 & , cons_alhl, cons_alhs, cons_cp)
368 !Phase changes for large scale cloud.
369  CALL meltfreeze_d(dt, t(i, j, k), td(i, j, k), ql_ls(i, j, k), &
370 & ql_lsd(i, j, k), qi_ls(i, j, k), qi_lsd(i, j, k), &
371 & t_ice_all, t_ice_max, icefrpwr, cons_alhl, cons_alhs&
372 & , cons_cp)
373 !Phase changes for convective cloud.
374  CALL meltfreeze_d(dt, t(i, j, k), td(i, j, k), ql_con(i, j, k), &
375 & ql_cond(i, j, k), qi_con(i, j, k), qi_cond(i, j, k)&
376 & , t_ice_all, t_ice_max, icefrpwr, cons_alhl, &
377 & cons_alhs, cons_cp)
378 !STAGE 1 - Compute convective clouds from RAS diagnostics
379  CALL convec_src_d(dt, mass(i, j, k), imass(i, j, k), t(i, j, k)&
380 & , td(i, j, k), q(i, j, k), qd(i, j, k), cnv_dqldt(i&
381 & , j, k), cnv_dqldtd(i, j, k), cnv_mfd(i, j, k), &
382 & cnv_mfdd(i, j, k), ql_con(i, j, k), ql_cond(i, j, k)&
383 & , qi_con(i, j, k), qi_cond(i, j, k), cf_con(i, j, k)&
384 & , cf_cond(i, j, k), qs(i, j, k), qsd(i, j, k), &
385 & cons_alhs, cons_alhl, cons_cp, t_ice_all, t_ice_max&
386 & , icefrpwr)
387 !STAGE 2a - Get PDF attributes
388  CALL pdf_width(ph(i, j, k), frland(i, j), maxrhcrit, &
389 & maxrhcritland, turnrhcrit, minrhcrit, pi_0, alpha)
390  IF (alpha .LT. 1.0 - rh00) THEN
391  alpha = 1.0 - rh00
392  ELSE
393  alpha = alpha
394  END IF
395  rhcrit = 1.0 - alpha
396 
397 !STAGE 2b - Use PDF to compute large scale cloud effects and diagnostics,
398 ! also update convection clouds
399 
400  if (do_moist_physics == 1) then
401 
402  !For data assimilation purposes always employ the perturbation model for cloud fraction
403  cloud_pertmod = 1
404 
405  elseif (do_moist_physics == 2) then
406 
407  !For longer forecasts only employ perturabtion model if filtering deems necessary
408  cloud_pertmod = 0
409 
410  !COMPUTE THE JACOBIAN OF LS_CLOUD AND USE RESULTS TO FILTER 'BAD' POINTS
411  jacobian = 0.0
412  DO ii = 1,8
413  xx = 0.0
414  xx(ii) = 1.0
415 
416  !Store seperate trajectory so as not to overwrite
417  ttraj = t(i,j,k)
418  qtraj = q(i,j,k)
419  qi_lstraj = qi_ls(i,j,k)
420  qi_contraj = qi_con(i,j,k)
421  ql_lstraj = ql_ls(i,j,k)
422  ql_contraj = ql_con(i,j,k)
423  cf_lstraj = cf_ls(i,j,k)
424  cf_contraj = cf_con(i,j,k)
425  phtraj = ph(i,j,k)
426 
427  tpert = xx(1)
428  qpert = xx(2)
429  qi_lspert = xx(3)
430  qi_conpert = xx(4)
431  ql_lspert = xx(5)
432  ql_conpert = xx(6)
433  cf_lspert = xx(7)
434  cf_conpert = xx(8)
435 
436  CALL ls_cloud_d(dt, alpha, pdfflag, phtraj, ttraj, tpert, qtraj, qpert, &
437  ql_lstraj, ql_lspert, ql_contraj, ql_conpert, &
438  qi_lstraj, qi_lspert, qi_contraj, qi_conpert, &
439  cf_lstraj, cf_lspert, cf_contraj, cf_conpert, &
440  cons_alhl, cons_alhf, cons_alhs, cons_cp, cons_h2omw, cons_airmw, &
441  t_ice_all, t_ice_max, icefrpwr, estblx, 0, do_moist_physics)
442 
443  jacobian(1,ii) = tpert
444  jacobian(2,ii) = qpert
445  jacobian(3,ii) = qi_lspert
446  jacobian(4,ii) = qi_conpert
447  jacobian(5,ii) = ql_lspert
448  jacobian(6,ii) = ql_conpert
449  jacobian(7,ii) = cf_lspert
450  jacobian(8,ii) = cf_conpert
451 
452  endDO
453 
454  !Compute eigenvalues of the Jacobian
455  a = jacobian
456 
457  lwork = -1
458  work = 0.0
459  info = 0
460 
461  CALL dgeev( 'Vectors', 'Vectors', n1, a, lda, wr, wi, vl, ldvl, vr, ldvr, work, lwork, info )
462 
463  lwork = min( lwmax, int( work( 1 ) ) )
464  CALL dgeev( 'Vectors', 'Vectors', n1, a, lda, wr, wi, vl, ldvl, vr, ldvr, work, lwork, info )
465 
466  maxeval = maxval(abs(wr))
467 
468  !Filter based on the eigenvalues
469  if (maxeval > 1.001) then
470  cloud_pertmod = 1
471  endif
472 
473  !Filter based on the Jacobian values
474  if ( ( jacobian(1,1) < 0.6 ) .or. &
475  ( jacobian(2,1) > 0.75e-4 ) .or. &
476  ( jacobian(5,1) < -0.75e-4 ) .or. &
477  ( jacobian(7,1) < -1.10 ) ) then
478  cloud_pertmod = 1
479  endif
480 
481  endif
482 
483  CALL ls_cloud_d(dt, alpha, pdfflag, ph(i, j, k), t(i, j, k), td(&
484 & i, j, k), q(i, j, k), qd(i, j, k), ql_ls(i, j, k), &
485 & ql_lsd(i, j, k), ql_con(i, j, k), ql_cond(i, j, k), &
486 & qi_ls(i, j, k), qi_lsd(i, j, k), qi_con(i, j, k), &
487 & qi_cond(i, j, k), cf_ls(i, j, k), cf_lsd(i, j, k), &
488 & cf_con(i, j, k), cf_cond(i, j, k), cons_alhl, &
489 & cons_alhf, cons_alhs, cons_cp, cons_h2omw, cons_airmw&
490 & , t_ice_all, t_ice_max, icefrpwr, estblx, &
491 & cloud_pertmod, do_moist_physics)
492 
493  !SAVE PRESINKS INPUTS
494  t_p_presink = td(i,j,k)
495  q_p_presink = qd(i,j,k)
496  qi_ls_p_presink = qi_lsd(i,j,k)
497  qi_con_p_presink = qi_cond(i,j,k)
498  ql_ls_p_presink = ql_lsd(i,j,k)
499  ql_con_p_presink = ql_cond(i,j,k)
500  !cf_con_p_presink = cf_cond(i,j,k)
501 
502 !Clean up where too much overall cloud.
503  cf_totd = cf_lsd(i, j, k) + cf_cond(i, j, k)
504  cf_tot = cf_ls(i, j, k) + cf_con(i, j, k)
505  IF (cf_tot .GT. 1.00) THEN
506  cf_lsd(i, j, k) = cf_lsd(i, j, k)/cf_tot - cf_ls(i, j, k)*&
507 & cf_totd/cf_tot**2
508  cf_ls(i, j, k) = cf_ls(i, j, k)*(1.00/cf_tot)
509  cf_cond(i, j, k) = cf_cond(i, j, k)/cf_tot - cf_con(i, j, k)*&
510 & cf_totd/cf_tot**2
511  cf_con(i, j, k) = cf_con(i, j, k)*(1.00/cf_tot)
512  END IF
513  cf_tot = cf_ls(i, j, k) + cf_con(i, j, k)
514 !STAGE 3 - Evap, Sublimation and Autoconversion
515 !Evaporation and sublimation of anvil cloud
516  CALL evap_cnv_d(dt, rhcrit, ph(i, j, k), t(i, j, k), td(i, j, k)&
517 & , q(i, j, k), qd(i, j, k), ql_con(i, j, k), ql_cond(i&
518 & , j, k), qi_con(i, j, k), qi_cond(i, j, k), cf_con(i, &
519 & j, k), cf_cond(i, j, k), cf_ls(i, j, k), qs(i, j, k), &
520 & qsd(i, j, k), rho_w, cld_evp_eff, cons_h2omw, &
521 & cons_airmw, cons_alhl, cons_rvap, cons_rgas, cons_pi, &
522 & cons_cp)
523  CALL subl_cnv_d(dt, rhcrit, ph(i, j, k), t(i, j, k), td(i, j, k)&
524 & , q(i, j, k), qd(i, j, k), ql_con(i, j, k), ql_cond(i&
525 & , j, k), qi_con(i, j, k), qi_cond(i, j, k), cf_con(i, &
526 & j, k), cf_cond(i, j, k), cf_ls(i, j, k), qs(i, j, k), &
527 & qsd(i, j, k), rho_w, cld_evp_eff, cons_h2omw, &
528 & cons_airmw, cons_alhl, cons_rvap, cons_rgas, cons_pi, &
529 & cons_cp, cons_alhs)
530 !Autoconversion
531  CALL autoconversion_ls_d(dt, ql_ls(i, j, k), ql_lsd(i, j, k), &
532 & qrn_ls, qrn_lsd, t(i, j, k), td(i, j, k), ph(&
533 & i, j, k), cf_ls(i, j, k), cf_lsd(i, j, k), &
534 & ls_sdqv2, ls_sdqv3, ls_sdqvt1, c_00, lwcrit, &
535 & dzet(i, j, k))
536  CALL autoconversion_cnv_d(dt, ql_con(i, j, k), ql_cond(i, j, k)&
537 & , qrn_an, qrn_and, t(i, j, k), td(i, j, k), &
538 & ph(i, j, k), cf_con(i, j, k), cf_cond(i, j, &
539 & k), anv_sdqv2, anv_sdqv3, anv_sdqvt1, c_00, &
540 & lwcrit, dzet(i, j, k))
541 !STAGE 4 - Fall and Re-evaporation of precip
542  CALL ice_settlefall_cnv_d(wrhodep, qi_con(i, j, k), qi_cond(i, j&
543 & , k), ph(i, j, k), t(i, j, k), td(i, j, k), &
544 & cf_con(i, j, k), cf_cond(i, j, k), cons_rgas&
545 & , khu(i, j), khl(i, j), k, dt, dzet(i, j, k)&
546 & , dzetd(i, j, k), qsn_an, qsn_and, &
547 & anv_icefall_c)
548  CALL ice_settlefall_ls_d(wrhodep, qi_ls(i, j, k), qi_lsd(i, j, k&
549 & ), ph(i, j, k), t(i, j, k), td(i, j, k), &
550 & cf_ls(i, j, k), cf_lsd(i, j, k), cons_rgas, &
551 & khu(i, j), khl(i, j), k, dt, dzet(i, j, k), &
552 & dzetd(i, j, k), qsn_ls, qsn_lsd, ls_icefall_c&
553 & )
554 !"Freeze" out any conv. precip, not done in RAS. This is
555 ! precip w/ large particles, so freezing is strict.
556  qtmp2 = 0.
557  IF (t(i, j, k) .LT. cons_tice) THEN
558  qtmp2 = qrn_cu_1d
559  qsn_cud = qrn_cu_1dd
560  qsn_cu = qrn_cu_1d
561  qrn_cu_1d = 0.
562  td(i, j, k) = td(i, j, k) + (cons_alhs-cons_alhl)*qsn_cud/&
563 & cons_cp
564  t(i, j, k) = t(i, j, k) + qsn_cu*(cons_alhs-cons_alhl)/cons_cp
565  qrn_cu_1dd = 0.0_8
566  ELSE
567  qsn_cud = 0.0_8
568  END IF
569 !Area
570  area_ls_prc1 = 0.0
571  area_upd_prc1 = 0.0
572  area_anv_prc1 = 0.0
573  tot_prec_updd = tot_prec_updd + mass(i, j, k)*(qrn_cu_1dd+&
574 & qsn_cud)
575  tot_prec_upd = tot_prec_upd + (qrn_cu_1d+qsn_cu)*mass(i, j, k)
576  area_upd_prcd = area_upd_prcd + mass(i, j, k)*(cnv_updfd(i, j, k&
577 & )*(qrn_cu_1d+qsn_cu)+cnv_updf(i, j, k)*(qrn_cu_1dd+qsn_cud))
578  area_upd_prc = area_upd_prc + cnv_updf(i, j, k)*(qrn_cu_1d+&
579 & qsn_cu)*mass(i, j, k)
580  tot_prec_anvd = tot_prec_anvd + mass(i, j, k)*(qrn_and+qsn_and)
581  tot_prec_anv = tot_prec_anv + (qrn_an+qsn_an)*mass(i, j, k)
582  area_anv_prcd = area_anv_prcd + mass(i, j, k)*(cf_cond(i, j, k)*&
583 & (qrn_an+qsn_an)+cf_con(i, j, k)*(qrn_and+qsn_and))
584  area_anv_prc = area_anv_prc + cf_con(i, j, k)*(qrn_an+qsn_an)*&
585 & mass(i, j, k)
586  tot_prec_lsd = tot_prec_lsd + mass(i, j, k)*(qrn_lsd+qsn_lsd)
587  tot_prec_ls = tot_prec_ls + (qrn_ls+qsn_ls)*mass(i, j, k)
588  area_ls_prcd = area_ls_prcd + mass(i, j, k)*(cf_lsd(i, j, k)*(&
589 & qrn_ls+qsn_ls)+cf_ls(i, j, k)*(qrn_lsd+qsn_lsd))
590  area_ls_prc = area_ls_prc + cf_ls(i, j, k)*(qrn_ls+qsn_ls)*mass(&
591 & i, j, k)
592  IF (tot_prec_anv .GT. 0.0) THEN
593  IF (area_anv_prc/tot_prec_anv .LT. 1.e-6) THEN
594  area_anv_prc1 = 1.e-6
595  area_anv_prc1d = 0.0_8
596  ELSE
597  area_anv_prc1d = (area_anv_prcd*tot_prec_anv-area_anv_prc*&
598 & tot_prec_anvd)/tot_prec_anv**2
599  area_anv_prc1 = area_anv_prc/tot_prec_anv
600  END IF
601  ELSE
602  area_anv_prc1d = 0.0_8
603  END IF
604  IF (tot_prec_upd .GT. 0.0) THEN
605  IF (area_upd_prc/tot_prec_upd .LT. 1.e-6) THEN
606  area_upd_prc1 = 1.e-6
607  area_upd_prc1d = 0.0_8
608  ELSE
609  area_upd_prc1d = (area_upd_prcd*tot_prec_upd-area_upd_prc*&
610 & tot_prec_updd)/tot_prec_upd**2
611  area_upd_prc1 = area_upd_prc/tot_prec_upd
612  END IF
613  ELSE
614  area_upd_prc1d = 0.0_8
615  END IF
616  IF (tot_prec_ls .GT. 0.0) THEN
617  IF (area_ls_prc/tot_prec_ls .LT. 1.e-6) THEN
618  area_ls_prc1 = 1.e-6
619  area_ls_prc1d = 0.0_8
620  ELSE
621  area_ls_prc1d = (area_ls_prcd*tot_prec_ls-area_ls_prc*&
622 & tot_prec_lsd)/tot_prec_ls**2
623  area_ls_prc1 = area_ls_prc/tot_prec_ls
624  END IF
625  ELSE
626  area_ls_prc1d = 0.0_8
627  END IF
628  area_ls_prc1d = ls_beta*area_ls_prc1d
629  area_ls_prc1 = ls_beta*area_ls_prc1
630  area_upd_prc1d = cnv_beta*area_upd_prc1d
631  area_upd_prc1 = cnv_beta*area_upd_prc1
632  area_anv_prc1d = anv_beta*area_anv_prc1d
633  area_anv_prc1 = anv_beta*area_anv_prc1
634  IF (k .EQ. lm) THEN
635 ! We have accumulated over the whole column
636  IF (tot_prec_anv .GT. 0.0) THEN
637  IF (area_anv_prc/tot_prec_anv .LT. 1.e-6) THEN
638  area_anv_prc = 1.e-6
639  area_anv_prcd = 0.0_8
640  ELSE
641  area_anv_prcd = (area_anv_prcd*tot_prec_anv-area_anv_prc*&
642 & tot_prec_anvd)/tot_prec_anv**2
643  area_anv_prc = area_anv_prc/tot_prec_anv
644  END IF
645  END IF
646  IF (tot_prec_upd .GT. 0.0) THEN
647  IF (area_upd_prc/tot_prec_upd .LT. 1.e-6) THEN
648  area_upd_prc = 1.e-6
649  area_upd_prcd = 0.0_8
650  ELSE
651  area_upd_prcd = (area_upd_prcd*tot_prec_upd-area_upd_prc*&
652 & tot_prec_updd)/tot_prec_upd**2
653  area_upd_prc = area_upd_prc/tot_prec_upd
654  END IF
655  END IF
656  IF (tot_prec_ls .GT. 0.0) THEN
657  IF (area_ls_prc/tot_prec_ls .LT. 1.e-6) THEN
658  area_ls_prc = 1.e-6
659  area_ls_prcd = 0.0_8
660  ELSE
661  area_ls_prcd = (area_ls_prcd*tot_prec_ls-area_ls_prc*&
662 & tot_prec_lsd)/tot_prec_ls**2
663  area_ls_prc = area_ls_prc/tot_prec_ls
664  END IF
665  END IF
666  area_ls_prcd = ls_beta*area_ls_prcd
667  area_ls_prc = ls_beta*area_ls_prc
668  area_upd_prcd = cnv_beta*area_upd_prcd
669  area_upd_prc = cnv_beta*area_upd_prc
670  area_anv_prcd = anv_beta*area_anv_prcd
671  area_anv_prc = anv_beta*area_anv_prc
672  END IF
673 !Get micro-physical constants
674  CALL cons_alhx_d(t(i, j, k), td(i, j, k), alhx3, alhx3d, &
675 & t_ice_max, t_ice_all, cons_alhs, cons_alhl)
676  CALL cons_microphys_d(t(i, j, k), td(i, j, k), ph(i, j, k), qs(i&
677 & , j, k), qsd(i, j, k), aa, aad, bb, bbd, &
678 & cons_h2omw, cons_airmw, cons_rvap, alhx3, alhx3d&
679 & )
680 !Precip Scheme Expects Total Cloud Liquid
681  qlt_tmpd = ql_lsd(i, j, k) + ql_cond(i, j, k)
682  qlt_tmp = ql_ls(i, j, k) + ql_con(i, j, k)
683  qit_tmpd = qi_lsd(i, j, k) + qi_cond(i, j, k)
684  qit_tmp = qi_ls(i, j, k) + qi_con(i, j, k)
685  prn_above_cu_oldd = prn_above_cu_newd
686  prn_above_cu_old = prn_above_cu_new
687  psn_above_cu_oldd = psn_above_cu_newd
688  psn_above_cu_old = psn_above_cu_new
689  evap_dd_cu_above_oldd = evap_dd_cu_above_newd
690  evap_dd_cu_above_old = evap_dd_cu_above_new
691  subl_dd_cu_above_oldd = subl_dd_cu_above_newd
692  subl_dd_cu_above_old = subl_dd_cu_above_new
693 !Precip and Evap for Convection
694  CALL precipandevap_d(k, ktop, lm, dt, frland(i, j), rhcrit, &
695 & qrn_cu_1d, qrn_cu_1dd, qsn_cu, qsn_cud, qlt_tmp, &
696 & qlt_tmpd, qit_tmp, t(i, j, k), td(i, j, k), q(i, &
697 & j, k), qd(i, j, k), mass(i, j, k), imass(i, j, k)&
698 & , ph(i, j, k), dzet(i, j, k), dzetd(i, j, k), &
699 & qddf3(i, j, k), qddf3d(i, j, k), aa, aad, bb, bbd&
700 & , area_upd_prc1, area_upd_prc1d, prn_above_cu_old&
701 & , prn_above_cu_oldd, prn_above_cu_new, &
702 & prn_above_cu_newd, psn_above_cu_old, &
703 & psn_above_cu_oldd, psn_above_cu_new, &
704 & psn_above_cu_newd, evap_dd_cu_above_old, &
705 & evap_dd_cu_above_oldd, evap_dd_cu_above_new, &
706 & evap_dd_cu_above_newd, subl_dd_cu_above_old, &
707 & subl_dd_cu_above_oldd, subl_dd_cu_above_new, &
708 & subl_dd_cu_above_newd, cnvenvfc, cnvddrfc, &
709 & cons_alhf, cons_alhs, cons_alhl, cons_cp, &
710 & cons_tice, cons_h2omw, cons_airmw, revap_off_p, &
711 & c_acc, c_ev_r, c_ev_s, rho_w, estblx)
712  prn_above_an_oldd = prn_above_an_newd
713  prn_above_an_old = prn_above_an_new
714  psn_above_an_oldd = psn_above_an_newd
715  psn_above_an_old = psn_above_an_new
716  evap_dd_an_above_oldd = evap_dd_an_above_newd
717  evap_dd_an_above_old = evap_dd_an_above_new
718  subl_dd_an_above_oldd = subl_dd_an_above_newd
719  subl_dd_an_above_old = subl_dd_an_above_new
720 !Precip and Evap for Anvil
721  anvenvfc = 1.0
722  CALL precipandevap_d(k, ktop, lm, dt, frland(i, j), rhcrit, &
723 & qrn_an, qrn_and, qsn_an, qsn_and, qlt_tmp, &
724 & qlt_tmpd, qit_tmp, t(i, j, k), td(i, j, k), q(i, &
725 & j, k), qd(i, j, k), mass(i, j, k), imass(i, j, k)&
726 & , ph(i, j, k), dzet(i, j, k), dzetd(i, j, k), &
727 & qddf3(i, j, k), qddf3d(i, j, k), aa, aad, bb, bbd&
728 & , area_anv_prc1, area_anv_prc1d, prn_above_an_old&
729 & , prn_above_an_oldd, prn_above_an_new, &
730 & prn_above_an_newd, psn_above_an_old, &
731 & psn_above_an_oldd, psn_above_an_new, &
732 & psn_above_an_newd, evap_dd_an_above_old, &
733 & evap_dd_an_above_oldd, evap_dd_an_above_new, &
734 & evap_dd_an_above_newd, subl_dd_an_above_old, &
735 & subl_dd_an_above_oldd, subl_dd_an_above_new, &
736 & subl_dd_an_above_newd, anvenvfc, anvddrfc, &
737 & cons_alhf, cons_alhs, cons_alhl, cons_cp, &
738 & cons_tice, cons_h2omw, cons_airmw, revap_off_p, &
739 & c_acc, c_ev_r, c_ev_s, rho_w, estblx)
740  prn_above_ls_oldd = prn_above_ls_newd
741  prn_above_ls_old = prn_above_ls_new
742  psn_above_ls_oldd = psn_above_ls_newd
743  psn_above_ls_old = psn_above_ls_new
744  evap_dd_ls_above_oldd = evap_dd_ls_above_newd
745  evap_dd_ls_above_old = evap_dd_ls_above_new
746  subl_dd_ls_above_oldd = subl_dd_ls_above_newd
747  subl_dd_ls_above_old = subl_dd_ls_above_new
748 !Precip and Evap for Large Scale
749  lsenvfc = 1.0
750  CALL precipandevap_d(k, ktop, lm, dt, frland(i, j), rhcrit, &
751 & qrn_ls, qrn_lsd, qsn_ls, qsn_lsd, qlt_tmp, &
752 & qlt_tmpd, qit_tmp, t(i, j, k), td(i, j, k), q(i, &
753 & j, k), qd(i, j, k), mass(i, j, k), imass(i, j, k)&
754 & , ph(i, j, k), dzet(i, j, k), dzetd(i, j, k), &
755 & qddf3(i, j, k), qddf3d(i, j, k), aa, aad, bb, bbd&
756 & , area_ls_prc1, area_ls_prc1d, prn_above_ls_old, &
757 & prn_above_ls_oldd, prn_above_ls_new, &
758 & prn_above_ls_newd, psn_above_ls_old, &
759 & psn_above_ls_oldd, psn_above_ls_new, &
760 & psn_above_ls_newd, evap_dd_ls_above_old, &
761 & evap_dd_ls_above_oldd, evap_dd_ls_above_new, &
762 & evap_dd_ls_above_newd, subl_dd_ls_above_old, &
763 & subl_dd_ls_above_oldd, subl_dd_ls_above_new, &
764 & subl_dd_ls_above_newd, lsenvfc, lsddrfc, &
765 & cons_alhf, cons_alhs, cons_alhl, cons_cp, &
766 & cons_tice, cons_h2omw, cons_airmw, revap_off_p, &
767 & c_acc, c_ev_r, c_ev_s, rho_w, estblx)
768  IF (ql_ls(i, j, k) + ql_con(i, j, k) .GT. 0.00) THEN
769  qt_tmpi_1d = -((ql_lsd(i, j, k)+ql_cond(i, j, k))/(ql_ls(i, j&
770 & , k)+ql_con(i, j, k))**2)
771  qt_tmpi_1 = 1./(ql_ls(i, j, k)+ql_con(i, j, k))
772  ELSE
773  qt_tmpi_1 = 0.0
774  qt_tmpi_1d = 0.0_8
775  END IF
776  ql_lsd(i, j, k) = ql_lsd(i, j, k)*qlt_tmp*qt_tmpi_1 + ql_ls(i, j&
777 & , k)*(qlt_tmpd*qt_tmpi_1+qlt_tmp*qt_tmpi_1d)
778  ql_ls(i, j, k) = ql_ls(i, j, k)*qlt_tmp*qt_tmpi_1
779  ql_cond(i, j, k) = ql_cond(i, j, k)*qlt_tmp*qt_tmpi_1 + ql_con(i&
780 & , j, k)*(qlt_tmpd*qt_tmpi_1+qlt_tmp*qt_tmpi_1d)
781  ql_con(i, j, k) = ql_con(i, j, k)*qlt_tmp*qt_tmpi_1
782  IF (qi_ls(i, j, k) + qi_con(i, j, k) .GT. 0.00) THEN
783  qt_tmpi_2d = -((qi_lsd(i, j, k)+qi_cond(i, j, k))/(qi_ls(i, j&
784 & , k)+qi_con(i, j, k))**2)
785  qt_tmpi_2 = 1./(qi_ls(i, j, k)+qi_con(i, j, k))
786  ELSE
787  qt_tmpi_2 = 0.0
788  qt_tmpi_2d = 0.0_8
789  END IF
790  qi_lsd(i, j, k) = qi_lsd(i, j, k)*qit_tmp*qt_tmpi_2 + qi_ls(i, j&
791 & , k)*(qit_tmpd*qt_tmpi_2+qit_tmp*qt_tmpi_2d)
792  qi_ls(i, j, k) = qi_ls(i, j, k)*qit_tmp*qt_tmpi_2
793  qi_cond(i, j, k) = qi_cond(i, j, k)*qit_tmp*qt_tmpi_2 + qi_con(i&
794 & , j, k)*(qit_tmpd*qt_tmpi_2+qit_tmp*qt_tmpi_2d)
795  qi_con(i, j, k) = qi_con(i, j, k)*qit_tmp*qt_tmpi_2
796 
797  !SINK FILTERING
798  if (do_moist_physics == 1) then
799  sinkfilt_ql = 0.65
800  sinkfilt_qi = 0.65
801  sinkfilt_cf = 1.0
802  elseif (do_moist_physics == 2) then
803  sinkfilt_ql = 0.9
804  sinkfilt_qi = 0.9
805  sinkfilt_cf = 1.0
806  endif
807 
808  !Sink reduction on convective high altitude cloud lidquid ice cloud
809  if (k < 50) then
810  qi_lsd(i,j,k) = sinkfilt_qi * qi_lsd(i,j,k) + (1.0-sinkfilt_qi) * qi_ls_p_presink
811  qi_cond(i,j,k) = sinkfilt_qi * qi_cond(i,j,k) + (1.0-sinkfilt_qi) * qi_con_p_presink
812  qd(i,j,k) = sinkfilt_qi * qd(i,j,k) + (1.0-sinkfilt_qi) * q_p_presink
813  endif
814 
815  !Sink reduction on cloud liquid water
816  if ( abs(k-62) .le. 2) then
817  ql_lsd(i,j,k) = sinkfilt_ql * ql_lsd(i,j,k) + (1.0-sinkfilt_ql) * ql_ls_p_presink
818  ql_cond(i,j,k) = sinkfilt_ql * ql_cond(i,j,k) + (1.0-sinkfilt_ql) * ql_con_p_presink
819  endif
820 
821  !cf_cond(i,j,k) = SINKfilt_CF * cf_cond(i,j,k) + (1.0-SINKfilt_CF) * cf_con_p_presink
822 
823  !TOTAL FILTERING
824  totfilt_t = 0.25
825  td(i,j,k) = totfilt_t * td(i,j,k) + (1.0-totfilt_t) * t_p_preall
826 
827  if (do_moist_physics == 1) then
828  totfilt_ql = 0.75
829  totfilt_qi = 1.0
830  elseif (do_moist_physics == 2) then
831  totfilt_ql = 0.5
832  totfilt_qi = 1.0!0.5
833  endif
834 
835  ql_lsd(i,j,k) = totfilt_ql * ql_lsd(i,j,k) + (1.0-totfilt_ql) * ql_ls_p_preall
836  ql_cond(i,j,k) = totfilt_ql * ql_cond(i,j,k) + (1.0-totfilt_ql) * ql_con_p_preall
837 
838  qi_lsd(i,j,k) = totfilt_qi * qi_lsd(i,j,k) + (1.0-totfilt_qi) * qi_ls_p_preall
839  qi_cond(i,j,k) = totfilt_qi * qi_cond(i,j,k) + (1.0-totfilt_qi) * qi_con_p_preall
840 
841  END DO
842  END DO
843  END DO
844 !Clean up of excess relative humidity
845  rhexcess = 1.1
846  CALL dqsat_bac_d(dqsdt, dqsdtd, qs, qsd, t, td, ph, im, jm, lm, estblx&
847 & , cons_h2omw, cons_airmw)
848  dqsd = 0.0_8
849  WHERE (q .GT. rhexcess*qs)
850  dqsd = ((qd-rhexcess*qsd)*(1.0+rhexcess*dqsdt*cons_alhl/cons_cp)-(q-&
851 & rhexcess*qs)*rhexcess*cons_alhl*dqsdtd/cons_cp)/(1.0+rhexcess*&
852 & dqsdt*cons_alhl/cons_cp)**2
853  dqs = (q-rhexcess*qs)/(1.0+rhexcess*dqsdt*cons_alhl/cons_cp)
854  ELSEWHERE
855  dqsd = 0.0_8
856  dqs = 0.0
857  END WHERE
858  qd = qd - dqsd
859  q = q - dqs
860  td = td + cons_alhl*dqsd/cons_cp
861  t = t + cons_alhl/cons_cp*dqs
862 !Clean up Q<0
863  DO j=1,jm
864  DO i=1,im
865 !Total precipitable water
866  tpwd = sum(dm(i, j, :)*qd(i, j, :))
867  tpw = sum(q(i, j, :)*dm(i, j, :))
868  negtpw = 0.
869  negtpwd = 0.0_8
870  DO l=1,lm
871  IF (q(i, j, l) .LT. 0.0) THEN
872  negtpwd = negtpwd + dm(i, j, l)*qd(i, j, l)
873  negtpw = negtpw + q(i, j, l)*dm(i, j, l)
874  qd(i, j, l) = 0.0_8
875  q(i, j, l) = 0.0
876  END IF
877  END DO
878  DO l=1,lm
879  IF (q(i, j, l) .GE. 0.0) THEN
880  qd(i, j, l) = qd(i, j, l)*(1.0+negtpw/(tpw-negtpw)) + q(i, j, &
881 & l)*(negtpwd*(tpw-negtpw)-negtpw*(tpwd-negtpwd))/(tpw-negtpw)&
882 & **2
883  q(i, j, l) = q(i, j, l)*(1.0+negtpw/(tpw-negtpw))
884  END IF
885  END DO
886  END DO
887  END DO
888 !Convert temperature back to potential temperature
889  thd = td/pih
890  th = t/pih
891 END SUBROUTINE cloud_driver_d
892 
893 ! Differentiation of cloud_tidy in forward (tangent) mode:
894 ! variations of useful results: af qv qla qlc qia qic cf te
895 ! with respect to varying inputs: af qv qla qlc qia qic cf te
896 !SUBROUTINES
897 SUBROUTINE cloud_tidy_d(qv, qvd, te, ted, qlc, qlcd, qic, qicd, cf, cfd&
898 & , qla, qlad, qia, qiad, af, afd, cons_alhl, cons_alhs, cons_cp)
899  IMPLICIT NONE
900  REAL*8, INTENT(INOUT) :: te, qv, qlc, cf, qla, af, qic, qia
901  REAL*8, INTENT(INOUT) :: ted, qvd, qlcd, cfd, qlad, afd, qicd, qiad
902  REAL*8, INTENT(IN) :: cons_alhl, cons_alhs, cons_cp
903 !Fix if Anvil cloud fraction too small
904  IF (af .LT. 1.e-5) THEN
905  qvd = qvd + qlad + qiad
906  qv = qv + qla + qia
907  ted = ted - cons_alhl*qlad/cons_cp - cons_alhs*qiad/cons_cp
908  te = te - cons_alhl/cons_cp*qla - cons_alhs/cons_cp*qia
909  af = 0.
910  qla = 0.
911  qia = 0.
912  afd = 0.0_8
913  qlad = 0.0_8
914  qiad = 0.0_8
915  END IF
916 !Fix if LS cloud fraction too small
917 ! if ( CF < 1.E-5 ) then
918 ! QV = QV + QLC + QIC
919 ! TE = TE - (CONS_ALHL/CONS_CP)*QLC - (CONS_ALHS/CONS_CP)*QIC
920 ! CF = 0.
921 ! QLC = 0.
922 ! QIC = 0.
923 ! end if
924 !LS LIQUID too small
925  IF (qlc .LT. 1.e-8) THEN
926  qvd = qvd + qlcd
927  qv = qv + qlc
928  ted = ted - cons_alhl*qlcd/cons_cp
929  te = te - cons_alhl/cons_cp*qlc
930  qlc = 0.
931  qlcd = 0.0_8
932  END IF
933 !LS ICE too small
934  IF (qic .LT. 1.e-8) THEN
935  qvd = qvd + qicd
936  qv = qv + qic
937  ted = ted - cons_alhs*qicd/cons_cp
938  te = te - cons_alhs/cons_cp*qic
939  qic = 0.
940  qicd = 0.0_8
941  END IF
942 !Anvil LIQUID too small
943  IF (qla .LT. 1.e-8) THEN
944  qvd = qvd + qlad
945  qv = qv + qla
946  ted = ted - cons_alhl*qlad/cons_cp
947  te = te - cons_alhl/cons_cp*qla
948  qla = 0.
949  qlad = 0.0_8
950  END IF
951 !Anvil ICE too small
952  IF (qia .LT. 1.e-8) THEN
953  qvd = qvd + qiad
954  qv = qv + qia
955  ted = ted - cons_alhs*qiad/cons_cp
956  te = te - cons_alhs/cons_cp*qia
957  qia = 0.
958  qiad = 0.0_8
959  END IF
960 !Fix ALL cloud quants if Anvil cloud LIQUID+ICE too small
961  IF (qla + qia .LT. 1.e-8) THEN
962  qvd = qvd + qlad + qiad
963  qv = qv + qla + qia
964  ted = ted - cons_alhl*qlad/cons_cp - cons_alhs*qiad/cons_cp
965  te = te - cons_alhl/cons_cp*qla - cons_alhs/cons_cp*qia
966  af = 0.
967  qla = 0.
968  qia = 0.
969  afd = 0.0_8
970  qlad = 0.0_8
971  qiad = 0.0_8
972  END IF
973 !Ditto if LS cloud LIQUID+ICE too small
974  IF (qlc + qic .LT. 1.e-8) THEN
975  qvd = qvd + qlcd + qicd
976  qv = qv + qlc + qic
977  ted = ted - cons_alhl*qlcd/cons_cp - cons_alhs*qicd/cons_cp
978  te = te - cons_alhl/cons_cp*qlc - cons_alhs/cons_cp*qic
979  cf = 0.
980  qlc = 0.
981  qic = 0.
982  qlcd = 0.0_8
983  qicd = 0.0_8
984  cfd = 0.0_8
985  END IF
986 END SUBROUTINE cloud_tidy_d
987 
988 ! Differentiation of meltfreeze in forward (tangent) mode:
989 ! variations of useful results: qi ql te
990 ! with respect to varying inputs: qi ql te
991 SUBROUTINE meltfreeze_d(dt, te, ted, ql, qld, qi, qid, t_ice_all, &
992 & t_ice_max, icefrpwr, cons_alhl, cons_alhs, cons_cp)
993  IMPLICIT NONE
994 !Inputs
995  REAL*8, INTENT(IN) :: dt, t_ice_all, t_ice_max
996  INTEGER, INTENT(IN) :: icefrpwr
997  REAL*8, INTENT(IN) :: cons_alhl, cons_alhs, cons_cp
998 !Prognostic
999  REAL*8, INTENT(INOUT) :: te, ql, qi
1000  REAL*8, INTENT(INOUT) :: ted, qld, qid
1001 !Locals
1002  REAL*8 :: fqi, dqil
1003  REAL*8 :: fqid, dqild
1004  REAL*8, PARAMETER :: taufrz=1000.
1005  INTRINSIC exp
1006  INTRINSIC max
1007  INTRINSIC min
1008  REAL*8 :: arg1
1009  REAL*8 :: arg1d
1010  fqi = 0.0
1011  dqil = 0.0
1012  CALL get_ice_fraction_d(te, ted, t_ice_all, t_ice_max, icefrpwr, fqi, &
1013 & fqid)
1014 !Freeze liquid
1015  IF (te .LE. t_ice_max) THEN
1016  arg1d = -(dt*fqid/taufrz)
1017  arg1 = -(dt*fqi/taufrz)
1018  dqild = qld*(1.0-exp(arg1)) - ql*arg1d*exp(arg1)
1019  dqil = ql*(1.0-exp(arg1))
1020  ELSE
1021  dqild = 0.0_8
1022  END IF
1023  IF (0. .LT. dqil) THEN
1024  dqil = dqil
1025  ELSE
1026  dqil = 0.
1027  dqild = 0.0_8
1028  END IF
1029  qid = qid + dqild
1030  qi = qi + dqil
1031  qld = qld - dqild
1032  ql = ql - dqil
1033  ted = ted + (cons_alhs-cons_alhl)*dqild/cons_cp
1034  te = te + (cons_alhs-cons_alhl)*dqil/cons_cp
1035  dqil = 0.
1036 !Melt ice instantly above 0^C
1037  IF (te .GT. t_ice_max) THEN
1038  dqild = -qid
1039  dqil = -qi
1040  ELSE
1041  dqild = 0.0_8
1042  END IF
1043  IF (0. .GT. dqil) THEN
1044  dqil = dqil
1045  ELSE
1046  dqil = 0.
1047  dqild = 0.0_8
1048  END IF
1049  qid = qid + dqild
1050  qi = qi + dqil
1051  qld = qld - dqild
1052  ql = ql - dqil
1053  ted = ted + (cons_alhs-cons_alhl)*dqild/cons_cp
1054  te = te + (cons_alhs-cons_alhl)*dqil/cons_cp
1055 END SUBROUTINE meltfreeze_d
1056 
1057 ! Differentiation of convec_src in forward (tangent) mode:
1058 ! variations of useful results: af qv qla qia te
1059 ! with respect to varying inputs: af qs qv qla qia dcf dmf te
1060 SUBROUTINE convec_src_d(dt, mass, imass, te, ted, qv, qvd, dcf, dcfd, &
1061 & dmf, dmfd, qla, qlad, qia, qiad, af, afd, qs, qsd, cons_alhs, &
1062 & cons_alhl, cons_cp, t_ice_all, t_ice_max, icefrpwr)
1063  IMPLICIT NONE
1064 !Inputs
1065  REAL*8, INTENT(IN) :: dt, t_ice_all, t_ice_max
1066  INTEGER, INTENT(IN) :: icefrpwr
1067  REAL*8, INTENT(IN) :: mass, imass, qs
1068  REAL*8, INTENT(IN) :: qsd
1069  REAL*8, INTENT(IN) :: dmf, dcf
1070  REAL*8, INTENT(IN) :: dmfd, dcfd
1071  REAL*8, INTENT(IN) :: cons_alhs, cons_alhl, cons_cp
1072 !Prognostic
1073  REAL*8, INTENT(INOUT) :: te, qv
1074  REAL*8, INTENT(INOUT) :: ted, qvd
1075  REAL*8, INTENT(INOUT) :: qla, qia, af
1076  REAL*8, INTENT(INOUT) :: qlad, qiad, afd
1077 !Locals
1078 !Minimum allowed env RH
1079  REAL*8, PARAMETER :: minrhx=0.001
1080  REAL*8 :: tend, qvx, fqi
1081  REAL*8 :: tendd, fqid
1082  INTRINSIC min
1083 !Namelist
1084 !DT - Timestep
1085 !MASS - Level Mass
1086 !iMASS - 1/Level Mass
1087 !TE - Temperature
1088 !QV - Specific Humidity
1089 !DCF - CNV_DQL from RAS
1090 !DMF - CNV_MFD from RAS
1091 !QLA - Convective cloud liquid water
1092 !QIA - Convective cloud liquid ice
1093 !AF - Convective cloud fraction
1094 !QS - Qsat
1095 !Zero out locals
1096  tend = 0.0
1097  qvx = 0.0
1098  fqi = 0.0
1099 !Addition of condensate from RAS
1100  tendd = imass*dcfd
1101  tend = dcf*imass
1102  CALL get_ice_fraction_d(te, ted, t_ice_all, t_ice_max, icefrpwr, fqi, &
1103 & fqid)
1104  qlad = qlad + dt*((1.0-fqi)*tendd-fqid*tend)
1105  qla = qla + (1.0-fqi)*tend*dt
1106  qiad = qiad + dt*(fqid*tend+fqi*tendd)
1107  qia = qia + fqi*tend*dt
1108 !Convective condensation has never frozen so latent heat of fusion
1109  ted = ted + (cons_alhs-cons_alhl)*dt*(fqid*tend+fqi*tendd)/cons_cp
1110  te = te + (cons_alhs-cons_alhl)*fqi*tend*dt/cons_cp
1111 !Compute Tiedtke-style anvil fraction
1112  tendd = imass*dmfd
1113  tend = dmf*imass
1114  afd = afd + dt*tendd
1115  af = af + tend*dt
1116  IF (af .GT. 0.99) THEN
1117  af = 0.99
1118  afd = 0.0_8
1119  ELSE
1120  af = af
1121  END IF
1122 ! Check for funny (tiny, negative) external QV, resulting from assumed QV=QSAT within anvil.
1123 ! Simply constrain AF assume condensate just gets "packed" in
1124  IF (af .LT. 1.0) THEN
1125  qvx = (qv-qs*af)/(1.-af)
1126  ELSE
1127  qvx = qs
1128  END IF
1129 !If saturated over critial value and there is Anvil
1130  IF (qvx - minrhx*qs .LT. 0.0 .AND. af .GT. 0.) THEN
1131  afd = ((qvd-minrhx*qsd)*qs*(1.0-minrhx)-(qv-minrhx*qs)*(1.0-minrhx)*&
1132 & qsd)/(qs*(1.0-minrhx))**2
1133  af = (qv-minrhx*qs)/(qs*(1.0-minrhx))
1134  END IF
1135  IF (af .LT. 0.) THEN
1136 ! If still cant make suitable env RH then destroy anvil
1137  af = 0.0
1138  qvd = qvd + qlad + qiad
1139  qv = qv + qla + qia
1140  ted = ted - (cons_alhl*qlad+cons_alhs*qiad)/cons_cp
1141  te = te - (cons_alhl*qla+cons_alhs*qia)/cons_cp
1142  qla = 0.0
1143  qia = 0.0
1144  afd = 0.0_8
1145  qlad = 0.0_8
1146  qiad = 0.0_8
1147  END IF
1148 END SUBROUTINE convec_src_d
1149 
1150 ! Differentiation of ls_cloud in forward (tangent) mode:
1151 ! variations of useful results: qai qal af qv qci qcl cf te
1152 ! with respect to varying inputs: qai qal af qv qci qcl cf te
1153 SUBROUTINE ls_cloud_d(dt, alpha, pdfshape, pl, te, ted, qv, qvd, qcl, &
1154 & qcld, qal, qald, qci, qcid, qai, qaid, cf, cfd, af, afd, cons_alhl, &
1155 & cons_alhf, cons_alhs, cons_cp, cons_h2omw, cons_airmw, t_ice_all, &
1156 & t_ice_max, icefrpwr, estblx, cloud_pertmod, dmp)
1157  IMPLICIT NONE
1158 !Inputs
1159  REAL*8, INTENT(IN) :: dt, alpha, pl, t_ice_all, t_ice_max
1160  INTEGER, INTENT(IN) :: pdfshape, cloud_pertmod, dmp
1161  INTEGER, INTENT(IN) :: icefrpwr
1162  REAL*8, INTENT(IN) :: cons_alhl, cons_alhf, cons_alhs, cons_cp, &
1163 & cons_h2omw, cons_airmw
1164  REAL*8, INTENT(IN) :: estblx(:)
1165 !Prognostic
1166  REAL*8, INTENT(INOUT) :: te, qv, qcl, qci, qal, qai, cf, af
1167  REAL*8, INTENT(INOUT) :: ted, qvd, qcld, qcid, qald, qaid, cfd, afd
1168 !Locals
1169  INTEGER :: n
1170  REAL*8 :: qco, cfo, qao, qt, qmx, qmn, dq
1171  REAL*8 :: qcod, cfod, qaod, qtd
1172  REAL*8 :: teo, qsx, dqsx, qs, dqs, tmparr
1173  REAL*8 :: teod, qsxd, dqsxd, dqsd, tmparrd
1174  REAL*8 :: qcx, qvx, cfx, qax, qc, qa, fqi, fqi_a, dqai, dqal, dqci, &
1175 & dqcl
1176  REAL*8 :: qcxd, qvxd, cfxd, qaxd, qcd, qad, fqid, dqaid, dqald, dqcid&
1177 & , dqcld
1178  REAL*8 :: ten, qsp, cfp, qvp, qcp
1179  REAL*8 :: tend, qcpd
1180  REAL*8 :: tep, qsn, cfn, qvn, qcn
1181  REAL*8 :: tepd, qsnd, cfnd, qcnd
1182  REAL*8 :: alhx, sigmaqt1, sigmaqt2
1183  REAL*8 :: alhxd, sigmaqt1d, sigmaqt2d
1184  REAL*8, DIMENSION(1) :: dqsx1, qsx1, teo1, pl1
1185  INTRINSIC max
1186 !Namelist
1187 !DT - Timestep
1188 !ALPHA - PDF half width
1189 !PL - Pressure (hPa)
1190 !TE - Temperature
1191 !QV - Specific humidity
1192 !QCl - Convective cloud liquid water
1193 !QAl - Large scale cloud liquid water
1194 !QCi - Convective cloud liquid ice
1195 !QAi - Large scale cloud liquid ice
1196 !CF - Large scale cloud fraction
1197 !AF - Convective cloud fraction
1198  qcd = qcld + qcid
1199  qc = qcl + qci
1200  qad = qald + qaid
1201  qa = qal + qai
1202  IF (qa .GT. 0.0) THEN
1203  fqi_a = qai/qa
1204  ELSE
1205  fqi_a = 0.0
1206  END IF
1207  teod = ted
1208  teo = te
1209  CALL dqsats_bac_d(dqsx, dqsxd, qsx, qsxd, teo, teod, pl, estblx, &
1210 & cons_h2omw, cons_airmw)
1211  IF (af .LT. 1.0) THEN
1212  IF (dmp .EQ. 1) THEN
1213  IF (1. - af .GT. 0.02) THEN
1214  tmparrd = -((-afd)/(1.-af)**2)
1215  tmparr = 1./(1.-af)
1216  ELSE
1217  tmparrd = -((-afd)/(0.02)**2)
1218  tmparr = 1./(1.-af)
1219  END IF
1220  ELSE IF (dmp .EQ. 2) THEN
1221  tmparrd = -((-afd)/(1.-af)**2)
1222  tmparr = 1./(1.-af)
1223  ELSE
1224  tmparrd = 0.0_8
1225  END IF
1226  ELSE
1227  tmparr = 0.0
1228  tmparrd = 0.0_8
1229  END IF
1230  cfxd = cfd*tmparr + cf*tmparrd
1231  cfx = cf*tmparr
1232  qcxd = qcd*tmparr + qc*tmparrd
1233  qcx = qc*tmparr
1234  qvxd = (qvd-qsxd*af-qsx*afd)*tmparr + (qv-qsx*af)*tmparrd
1235  qvx = (qv-qsx*af)*tmparr
1236  IF (af .GE. 1.0) THEN
1237  qvxd = 1.e-4*qsxd
1238  qvx = qsx*1.e-4
1239  END IF
1240  IF (af .GT. 0.) THEN
1241  qaxd = (qad*af-qa*afd)/af**2
1242  qax = qa/af
1243  ELSE
1244  qax = 0.
1245  qaxd = 0.0_8
1246  END IF
1247  qtd = qcxd + qvxd
1248  qt = qcx + qvx
1249  tep = teo
1250  qsn = qsx
1251  tend = teod
1252  ten = teo
1253  cfnd = cfxd
1254  cfn = cfx
1255  qvn = qvx
1256  qcnd = qcxd
1257  qcn = qcx
1258  dqs = dqsx
1259 !Begin iteration
1260 !do n=1,4
1261  n = 1
1262  qsp = qsn
1263  qvp = qvn
1264  qcpd = qcnd
1265  qcp = qcn
1266  cfp = cfn
1267 !Dont call again as not looping
1268  dqsd = dqsxd
1269  dqs = dqsx
1270  qsnd = qsxd
1271  qsn = qsx
1272 !call DQSATs_BAC(DQS, QSn, TEn, PL, ESTBLX, CONS_H2OMW, CONS_AIRMW)
1273  tepd = tend
1274  tep = ten
1275  CALL get_ice_fraction_d(tep, tepd, t_ice_all, t_ice_max, icefrpwr, fqi&
1276 & , fqid)
1277  sigmaqt1d = alpha*qsnd
1278  sigmaqt1 = alpha*qsn
1279  sigmaqt2d = alpha*qsnd
1280  sigmaqt2 = alpha*qsn
1281  IF (pdfshape .EQ. 2) THEN
1282 !For triangular, symmetric: sigmaqt1 = sigmaqt2 = alpha*qsn (alpha is half width)
1283 !For triangular, skewed r : sigmaqt1 < sigmaqt2
1284  sigmaqt1d = alpha*qsnd
1285  sigmaqt1 = alpha*qsn
1286  sigmaqt2d = alpha*qsnd
1287  sigmaqt2 = alpha*qsn
1288  END IF
1289 !Compute cloud fraction
1290  IF (cloud_pertmod .EQ. 0) THEN
1291  CALL pdffrac_d(1, qt, qtd, sigmaqt1, sigmaqt1d, sigmaqt2, sigmaqt2d&
1292 & , qsn, qsnd, cfn, cfnd)
1293  ELSE IF (cloud_pertmod .EQ. 1) THEN
1294  CALL pdffrac_d(4, qt, qtd, sigmaqt1, sigmaqt1d, sigmaqt2, sigmaqt2d&
1295 & , qsn, qsnd, cfn, cfnd)
1296  END IF
1297 !Compute cloud condensate
1298  CALL pdfcondensate_d(pdfshape, qt, qtd, sigmaqt1, sigmaqt1d, sigmaqt2&
1299 & , sigmaqt2d, qsn, qsnd, qcn, qcnd)
1300 !Adjustments to anvil condensate due to the assumption of a stationary TOTAL
1301 !water PDF subject to a varying QSAT value during the iteration
1302  IF (af .GT. 0.) THEN
1303 ! + QSx - QS
1304  qaod = qaxd
1305  qao = qax
1306  ELSE
1307  qao = 0.
1308  qaod = 0.0_8
1309  END IF
1310  alhxd = cons_alhs*fqid - cons_alhl*fqid
1311  alhx = (1.0-fqi)*cons_alhl + fqi*cons_alhs
1312  IF (pdfshape .EQ. 1) THEN
1313  qcnd = qcpd + ((qcnd-qcpd)*(1.-(cfn*(alpha-1.)-qcn/qsn)*dqs*alhx/&
1314 & cons_cp)+(qcn-qcp)*(((alpha-1.)*cfnd-(qcnd*qsn-qcn*qsnd)/qsn**2)*&
1315 & dqs*alhx+(cfn*(alpha-1.)-qcn/qsn)*(dqsd*alhx+dqs*alhxd))/cons_cp)/&
1316 & (1.-(cfn*(alpha-1.)-qcn/qsn)*dqs*alhx/cons_cp)**2
1317  qcn = qcp + (qcn-qcp)/(1.-(cfn*(alpha-1.)-qcn/qsn)*dqs*alhx/cons_cp)
1318  ELSE IF (pdfshape .EQ. 2) THEN
1319 !This next line needs correcting - need proper d(del qc)/dT derivative for triangular
1320 !for now, just use relaxation of 1/2.
1321  IF (n .NE. 4) THEN
1322  qcnd = qcpd + 0.5*(qcnd-qcpd)
1323  qcn = qcp + (qcn-qcp)*0.5
1324  END IF
1325  END IF
1326  qvn = qvp - (qcn-qcp)
1327  ten = tep + (1.0-fqi)*(cons_alhl/cons_cp)*((qcn-qcp)*(1.-af)+(qao-qax)&
1328 & *af) + fqi*(cons_alhs/cons_cp)*((qcn-qcp)*(1.-af)+(qao-qax)*af)
1329 !enddo ! qsat iteration
1330  cfod = cfnd
1331  cfo = cfn
1332  cf = cfn
1333  qcod = qcnd
1334  qco = qcn
1335  teo = ten
1336 ! Update prognostic variables. QCo, QAo become updated grid means.
1337  IF (af .LT. 1.0) THEN
1338  cfd = cfod*(1.-af) - cfo*afd
1339  cf = cfo*(1.-af)
1340  qcod = qcod*(1.-af) - qco*afd
1341  qco = qco*(1.-af)
1342  qaod = qaod*af + qao*afd
1343  qao = qao*af
1344  ELSE
1345 !Grid box filled with anvil
1346 ! Special case AF=1, i.e., box filled with anvil. Note: no guarantee QV_box > QS_box
1347 ! Remove any other cloud
1348  cf = 0.
1349 ! Add any LS condensate to anvil type
1350  qaod = qad + qcd
1351  qao = qa + qc
1352 ! Remove same from LS
1353  qco = 0.
1354 ! Total water
1355  qtd = qaod + qvd
1356  qt = qao + qv
1357  IF (qt - qsx .LT. 0.) THEN
1358  qao = 0.
1359  cfd = 0.0_8
1360  qaod = 0.0_8
1361  qcod = 0.0_8
1362  ELSE
1363  qaod = qtd - qsxd
1364  qao = qt - qsx
1365  cfd = 0.0_8
1366  qcod = 0.0_8
1367  END IF
1368  END IF
1369 !Partition new condensate into ice and liquid taking care to keep both >=0 separately.
1370 !New condensate can be less than old, so Delta can be < 0.
1371  qcxd = qcod - qcd
1372  qcx = qco - qc
1373  dqcld = (1.0-fqi)*qcxd - fqid*qcx
1374  dqcl = (1.0-fqi)*qcx
1375  dqcid = fqid*qcx + fqi*qcxd
1376  dqci = fqi*qcx
1377 !Large Scale Partition
1378  IF (qcl + dqcl .LT. 0.) THEN
1379  dqcid = dqcid + qcld + dqcld
1380  dqci = dqci + (qcl+dqcl)
1381 !== dQCl - (QCl+dQCl)
1382  dqcld = -qcld
1383  dqcl = -qcl
1384  END IF
1385  IF (qci + dqci .LT. 0.) THEN
1386  dqcld = dqcld + qcid + dqcid
1387  dqcl = dqcl + (qci+dqci)
1388 !== dQCi - (QCi+dQCi)
1389  dqcid = -qcid
1390  dqci = -qci
1391  END IF
1392  qaxd = qaod - qad
1393  qax = qao - qa
1394 ! (1.0-fQi)*QAx
1395  dqald = qaxd
1396  dqal = qax
1397 ! fQi * QAx
1398  dqai = 0.
1399 !Convective partition
1400  IF (qal + dqal .LT. 0.) THEN
1401  dqaid = qald + dqald
1402  dqai = dqai + (qal+dqal)
1403  dqald = -qald
1404  dqal = -qal
1405  ELSE
1406  dqaid = 0.0_8
1407  END IF
1408  IF (qai + dqai .LT. 0.) THEN
1409  dqald = dqald + qaid + dqaid
1410  dqal = dqal + (qai+dqai)
1411  dqaid = -qaid
1412  dqai = -qai
1413  END IF
1414 ! Clean-up cloud if fractions are too small
1415  IF (af .LT. 1.e-5) THEN
1416  dqaid = -qaid
1417  dqai = -qai
1418  dqald = -qald
1419  dqal = -qal
1420  END IF
1421  IF (cf .LT. 1.e-5) THEN
1422  dqcid = -qcid
1423  dqci = -qci
1424  dqcld = -qcld
1425  dqcl = -qcl
1426  END IF
1427  qaid = qaid + dqaid
1428  qai = qai + dqai
1429  qald = qald + dqald
1430  qal = qal + dqal
1431  qcid = qcid + dqcid
1432  qci = qci + dqci
1433  qcld = qcld + dqcld
1434  qcl = qcl + dqcl
1435 !Update specific humidity
1436  qvd = qvd - dqaid - dqcid - dqald - dqcld
1437  qv = qv - (dqai+dqci+dqal+dqcl)
1438 !Update temperature
1439  ted = ted + (cons_alhl*(dqaid+dqcid+dqald+dqcld)+cons_alhf*(dqaid+&
1440 & dqcid))/cons_cp
1441  te = te + (cons_alhl*(dqai+dqci+dqal+dqcl)+cons_alhf*(dqai+dqci))/&
1442 & cons_cp
1443 !Take care of situations where QS moves past QA during QSAT iteration (QAo negative).
1444 !"Evaporate" offending QA
1445  IF (qao .LE. 0.) THEN
1446  qvd = qvd + qaid + qald
1447  qv = qv + qai + qal
1448  ted = ted - cons_alhs*qaid/cons_cp - cons_alhl*qald/cons_cp
1449  te = te - cons_alhs/cons_cp*qai - cons_alhl/cons_cp*qal
1450  qai = 0.
1451  qal = 0.
1452  af = 0.
1453  qaid = 0.0_8
1454  qald = 0.0_8
1455  afd = 0.0_8
1456  END IF
1457 END SUBROUTINE ls_cloud_d
1458 
1459 ! Differentiation of pdffrac in forward (tangent) mode:
1460 ! variations of useful results: clfrac
1461 ! with respect to varying inputs: qtmean sigmaqt1 sigmaqt2 qstar
1462 ! clfrac
1463 SUBROUTINE pdffrac_d(flag, qtmean, qtmeand, sigmaqt1, sigmaqt1d, &
1464 & sigmaqt2, sigmaqt2d, qstar, qstard, clfrac, clfracd)
1465  IMPLICIT NONE
1466 !Regularization
1467 !clfracd = 0.2*clfracd
1468 !Inputs
1469  INTEGER, INTENT(IN) :: flag
1470  REAL*8, INTENT(IN) :: qtmean, sigmaqt1, sigmaqt2, qstar
1471  REAL*8, INTENT(IN) :: qtmeand, sigmaqt1d, sigmaqt2d, qstard
1472 !Prognostic
1473  REAL*8, INTENT(INOUT) :: clfrac
1474  REAL*8, INTENT(INOUT) :: clfracd
1475 !LOCALS
1476  REAL*8 :: qtmode, qtmin, qtmax
1477  REAL*8 :: qtmoded, qtmind, qtmaxd
1478  REAL*8 :: rh, rhd, q1, q2
1479  REAL*8 :: rhd0
1480  INTRINSIC min
1481  INTRINSIC tanh
1482  REAL*8 :: min1
1483  REAL*8 :: min1d
1484  IF (flag .EQ. 1) THEN
1485 !Tophat PDF
1486  IF (qtmean + sigmaqt1 .LT. qstar) THEN
1487  clfrac = 0.
1488  clfracd = 0.0_8
1489  ELSE IF (sigmaqt1 .GT. 0.) THEN
1490  IF (qtmean + sigmaqt1 - qstar .GT. 2.*sigmaqt1) THEN
1491  min1d = 2.*sigmaqt1d
1492  min1 = 2.*sigmaqt1
1493  ELSE
1494  min1d = qtmeand + sigmaqt1d - qstard
1495  min1 = qtmean + sigmaqt1 - qstar
1496  END IF
1497  clfracd = (min1d*2.*sigmaqt1-min1*2.*sigmaqt1d)/(2.*sigmaqt1)**2
1498  clfrac = min1/(2.*sigmaqt1)
1499  ELSE
1500  clfrac = 1.
1501  clfracd = 0.0_8
1502  END IF
1503  ELSE IF (flag .EQ. 2) THEN
1504 !Triangular PDF
1505  qtmoded = qtmeand + (sigmaqt1d-sigmaqt2d)/3.
1506  qtmode = qtmean + (sigmaqt1-sigmaqt2)/3.
1507  IF (qtmode - sigmaqt1 .GT. 0.) THEN
1508  qtmin = 0.
1509  qtmind = 0.0_8
1510  ELSE
1511  qtmind = qtmoded - sigmaqt1d
1512  qtmin = qtmode - sigmaqt1
1513  END IF
1514  qtmaxd = qtmoded + sigmaqt2d
1515  qtmax = qtmode + sigmaqt2
1516  IF (qtmax .LT. qstar) THEN
1517  clfrac = 0.
1518  clfracd = 0.0_8
1519  ELSE IF (qtmode .LE. qstar .AND. qstar .LT. qtmax) THEN
1520  clfracd = (((qtmaxd-qstard)*(qtmax-qstar)+(qtmax-qstar)*(qtmaxd-&
1521 & qstard))*(qtmax-qtmin)*(qtmax-qtmode)-(qtmax-qstar)**2*((qtmaxd-&
1522 & qtmind)*(qtmax-qtmode)+(qtmax-qtmin)*(qtmaxd-qtmoded)))/((qtmax-&
1523 & qtmin)*(qtmax-qtmode))**2
1524  clfrac = (qtmax-qstar)*(qtmax-qstar)/((qtmax-qtmin)*(qtmax-qtmode)&
1525 & )
1526  ELSE IF (qtmin .LE. qstar .AND. qstar .LT. qtmode) THEN
1527  clfracd = -((((qstard-qtmind)*(qstar-qtmin)+(qstar-qtmin)*(qstard-&
1528 & qtmind))*(qtmax-qtmin)*(qtmode-qtmin)-(qstar-qtmin)**2*((qtmaxd-&
1529 & qtmind)*(qtmode-qtmin)+(qtmax-qtmin)*(qtmoded-qtmind)))/((qtmax-&
1530 & qtmin)*(qtmode-qtmin))**2)
1531  clfrac = 1. - (qstar-qtmin)*(qstar-qtmin)/((qtmax-qtmin)*(qtmode-&
1532 & qtmin))
1533  ELSE IF (qstar .LE. qtmin) THEN
1534  clfrac = 1.
1535  clfracd = 0.0_8
1536  END IF
1537  ELSE IF (flag .EQ. 3) THEN
1538 
1539  !Tophat PDF for the reference part
1540  IF (qtmean + sigmaqt1 .LT. qstar) THEN
1541  clfrac = 0.
1542  ELSE IF (sigmaqt1 .GT. 0.) THEN
1543  IF (qtmean + sigmaqt1 - qstar .GT. 2.*sigmaqt1) THEN
1544  min1d = 2.*sigmaqt1d
1545  min1 = 2.*sigmaqt1
1546  ELSE
1547  min1d = qtmeand + sigmaqt1d - qstard
1548  min1 = qtmean + sigmaqt1 - qstar
1549  END IF
1550  clfrac = min1/(2.*sigmaqt1)
1551  ELSE
1552  clfrac = 1.
1553  END IF
1554 
1555  !TANH function for the perturabtions
1556  rhd0 = (qtmeand*qstar-qtmean*qstard)/qstar**2
1557  rh = qtmean/qstar
1558  q1 = 22.556
1559  clfracd = 0.5*q1*rhd0*(1.0-tanh(q1*(rh-1.0))**2)
1560 
1561  ! (REGULARIZATION) * (GRADIENT) * (PERTURBATION)
1562  clfracd = (0.66*( cosh(10*(rh-1.0))**-2)) * clfracd
1563 
1564  ELSE IF (flag .EQ. 4) THEN
1565 
1566  !Tophat PDF for the reference part
1567  IF (qtmean + sigmaqt1 .LT. qstar) THEN
1568  clfrac = 0.
1569  ELSE IF (sigmaqt1 .GT. 0.) THEN
1570  IF (qtmean + sigmaqt1 - qstar .GT. 2.*sigmaqt1) THEN
1571  min1d = 2.*sigmaqt1d
1572  min1 = 2.*sigmaqt1
1573  ELSE
1574  min1d = qtmeand + sigmaqt1d - qstard
1575  min1 = qtmean + sigmaqt1 - qstar
1576  END IF
1577  clfrac = min1/(2.*sigmaqt1)
1578  ELSE
1579  clfrac = 1.
1580  END IF
1581 
1582  !Linear for the perturbation part
1583  rhd0 = (qtmeand*qstar-qtmean*qstard)/qstar**2
1584  rh = qtmean/qstar
1585  q1 = 0.9335
1586  q2 = 1.0665
1587  IF (rh .LT. q1) THEN
1588  clfracd = 0.0_8
1589  ELSE IF (rh .GE. q1 .AND. rh .LT. q2) THEN
1590  clfracd = rhd0/((q2/q1-1)*q1)
1591  ELSE
1592  clfracd = 0.0_8
1593  END IF
1594 
1595  !Regularization
1596  clfracd = clfracd * 0.2
1597 
1598  END IF
1599 
1600 END SUBROUTINE pdffrac_d
1601 
1602 ! Differentiation of pdfcondensate in forward (tangent) mode:
1603 ! variations of useful results: condensate4
1604 ! with respect to varying inputs: qtmean4 qstar4 sigmaqt14 sigmaqt24
1605 SUBROUTINE pdfcondensate_d(flag, qtmean4, qtmean4d, sigmaqt14, &
1606 & sigmaqt14d, sigmaqt24, sigmaqt24d, qstar4, qstar4d, condensate4, &
1607 & condensate4d)
1608  IMPLICIT NONE
1609 !Inputs
1610  INTEGER, INTENT(IN) :: flag
1611  REAL*8, INTENT(IN) :: qtmean4, sigmaqt14, sigmaqt24, qstar4
1612  REAL*8, INTENT(IN) :: qtmean4d, sigmaqt14d, sigmaqt24d, qstar4d
1613 !Prognostic
1614  REAL*8, INTENT(INOUT) :: condensate4
1615  REAL*8, INTENT(INOUT) :: condensate4d
1616 !Locals
1617  REAL*8 :: qtmode, qtmin, qtmax, consta, constb, cloudf
1618  REAL*8 :: qtmoded, qtmind, qtmaxd, constad, constbd, cloudfd
1619  REAL*8 :: term1, term2, term3
1620  REAL*8 :: term1d, term2d, term3d
1621  REAL*8 :: qtmean, sigmaqt1, sigmaqt2, qstar, condensate
1622  REAL*8 :: qtmeand, sigmaqt1d, sigmaqt2d, qstard, condensated
1623  INTRINSIC min
1624  REAL*8 :: min1
1625  REAL*8 :: min1d
1626  qtmeand = qtmean4d
1627  qtmean = qtmean4
1628  sigmaqt1d = sigmaqt14d
1629  sigmaqt1 = sigmaqt14
1630  sigmaqt2d = sigmaqt24d
1631  sigmaqt2 = sigmaqt24
1632  qstard = qstar4d
1633  qstar = qstar4
1634  IF (flag .EQ. 1) THEN
1635  IF (qtmean + sigmaqt1 .LT. qstar) THEN
1636  condensate = 0.d0
1637  condensated = 0.0_8
1638  ELSE IF (qstar .GT. qtmean - sigmaqt1) THEN
1639  IF (sigmaqt1 .GT. 0.d0) THEN
1640  IF (qtmean + sigmaqt1 - qstar .GT. 2.d0*sigmaqt1) THEN
1641  min1d = 2.d0*sigmaqt1d
1642  min1 = 2.d0*sigmaqt1
1643  ELSE
1644  min1d = qtmeand + sigmaqt1d - qstard
1645  min1 = qtmean + sigmaqt1 - qstar
1646  END IF
1647  condensated = (2*min1*min1d*4.d0*sigmaqt1-min1**2*4.d0*sigmaqt1d&
1648 & )/(4.d0*sigmaqt1)**2
1649  condensate = min1**2/(4.d0*sigmaqt1)
1650  ELSE
1651  condensated = qtmeand - qstard
1652  condensate = qtmean - qstar
1653  END IF
1654  ELSE
1655  condensated = qtmeand - qstard
1656  condensate = qtmean - qstar
1657  END IF
1658  ELSE IF (flag .EQ. 2) THEN
1659  qtmoded = qtmeand + (sigmaqt1d-sigmaqt2d)/3.d0
1660  qtmode = qtmean + (sigmaqt1-sigmaqt2)/3.d0
1661  IF (qtmode - sigmaqt1 .GT. 0.d0) THEN
1662  qtmin = 0.d0
1663  qtmind = 0.0_8
1664  ELSE
1665  qtmind = qtmoded - sigmaqt1d
1666  qtmin = qtmode - sigmaqt1
1667  END IF
1668  qtmaxd = qtmoded + sigmaqt2d
1669  qtmax = qtmode + sigmaqt2
1670  IF (qtmax .LT. qstar) THEN
1671  condensate = 0.d0
1672  condensated = 0.0_8
1673  ELSE IF (qtmode .LE. qstar .AND. qstar .LT. qtmax) THEN
1674  constbd = -(2.d0*((qtmaxd-qtmind)*(qtmax-qtmode)+(qtmax-qtmin)*(&
1675 & qtmaxd-qtmoded))/((qtmax-qtmin)*(qtmax-qtmode))**2)
1676  constb = 2.d0/((qtmax-qtmin)*(qtmax-qtmode))
1677  cloudfd = (((qtmaxd-qstard)*(qtmax-qstar)+(qtmax-qstar)*(qtmaxd-&
1678 & qstard))*(qtmax-qtmin)*(qtmax-qtmode)-(qtmax-qstar)**2*((qtmaxd-&
1679 & qtmind)*(qtmax-qtmode)+(qtmax-qtmin)*(qtmaxd-qtmoded)))/((qtmax-&
1680 & qtmin)*(qtmax-qtmode))**2
1681  cloudf = (qtmax-qstar)*(qtmax-qstar)/((qtmax-qtmin)*(qtmax-qtmode)&
1682 & )
1683  term1d = ((qstard*qstar+qstar*qstard)*qstar+qstar**2*qstard)/3.d0
1684  term1 = qstar*qstar*qstar/3.d0
1685  term2d = ((qtmaxd*qstar+qtmax*qstard)*qstar+qtmax*qstar*qstard)/&
1686 & 2.d0
1687  term2 = qtmax*qstar*qstar/2.d0
1688  term3d = ((qtmaxd*qtmax+qtmax*qtmaxd)*qtmax+qtmax**2*qtmaxd)/6.d0
1689  term3 = qtmax*qtmax*qtmax/6.d0
1690  condensated = constbd*(term1-term2+term3) + constb*(term1d-term2d+&
1691 & term3d) - qstard*cloudf - qstar*cloudfd
1692  condensate = constb*(term1-term2+term3) - qstar*cloudf
1693  ELSE IF (qtmin .LE. qstar .AND. qstar .LT. qtmode) THEN
1694  constad = -(2.d0*((qtmaxd-qtmind)*(qtmode-qtmin)+(qtmax-qtmin)*(&
1695 & qtmoded-qtmind))/((qtmax-qtmin)*(qtmode-qtmin))**2)
1696  consta = 2.d0/((qtmax-qtmin)*(qtmode-qtmin))
1697  cloudfd = -((((qstard-qtmind)*(qstar-qtmin)+(qstar-qtmin)*(qstard-&
1698 & qtmind))*(qtmax-qtmin)*(qtmode-qtmin)-(qstar-qtmin)**2*((qtmaxd-&
1699 & qtmind)*(qtmode-qtmin)+(qtmax-qtmin)*(qtmoded-qtmind)))/((qtmax-&
1700 & qtmin)*(qtmode-qtmin))**2)
1701  cloudf = 1.d0 - (qstar-qtmin)*(qstar-qtmin)/((qtmax-qtmin)*(qtmode&
1702 & -qtmin))
1703  term1d = ((qstard*qstar+qstar*qstard)*qstar+qstar**2*qstard)/3.d0
1704  term1 = qstar*qstar*qstar/3.d0
1705  term2d = ((qtmind*qstar+qtmin*qstard)*qstar+qtmin*qstar*qstard)/&
1706 & 2.d0
1707  term2 = qtmin*qstar*qstar/2.d0
1708  term3d = ((qtmind*qtmin+qtmin*qtmind)*qtmin+qtmin**2*qtmind)/6.d0
1709  term3 = qtmin*qtmin*qtmin/6.d0
1710  condensated = qtmeand - constad*(term1-term2+term3) - consta*(&
1711 & term1d-term2d+term3d) - qstard*cloudf - qstar*cloudfd
1712  condensate = qtmean - consta*(term1-term2+term3) - qstar*cloudf
1713  ELSE IF (qstar .LE. qtmin) THEN
1714  condensated = qtmeand - qstard
1715  condensate = qtmean - qstar
1716  ELSE
1717  condensated = 0.0_8
1718  END IF
1719  ELSE IF (flag .EQ. 3) THEN
1720 !Reference part done normally
1721 !IF (qtmean + sigmaqt1 .LT. qstar) THEN
1722 ! condensate = 0.d0
1723 !ELSE IF (qstar .GT. qtmean - sigmaqt1) THEN
1724 ! IF (sigmaqt1 .GT. 0.d0) THEN
1725 ! IF (qtmean + sigmaqt1 - qstar .GT. 2.d0*sigmaqt1) THEN
1726 ! min1 = 2.d0*sigmaqt1
1727 ! ELSE
1728 ! min1 = qtmean + sigmaqt1 - qstar
1729 ! END IF
1730 ! condensate = min1**2/(4.d0*sigmaqt1)
1731 ! ELSE
1732 ! condensate = qtmean - qstar
1733 ! END IF
1734 !ELSE
1735 ! condensate = qtmean - qstar
1736 !END IF
1737 !Perturbation part from linear
1738  IF (qtmean - qstar .GT. -0.5e-3) THEN
1739  condensated = qtmeand - qstard
1740  condensate = qtmean - qstar
1741  ELSE
1742  condensate = 0.0
1743  condensated = 0.0_8
1744  END IF
1745  ELSE
1746  condensated = 0.0_8
1747  END IF
1748  condensate4d = condensated
1749  condensate4 = condensate
1750 END SUBROUTINE pdfcondensate_d
1751 
1752 ! Differentiation of evap_cnv in forward (tangent) mode:
1753 ! variations of useful results: f ql qv te
1754 ! with respect to varying inputs: f qi ql qs qv te
1755 SUBROUTINE evap_cnv_d(dt, rhcr, pl, te, ted, qv, qvd, ql, qld, qi, qid, &
1756 & f, fd, xf, qs, qsd, rho_w, cld_evp_eff, cons_h2omw, cons_airmw, &
1757 & cons_alhl, cons_rvap, cons_rgas, cons_pi, cons_cp)
1758  IMPLICIT NONE
1759 !Inputs
1760  REAL*8, INTENT(IN) :: dt, rhcr, pl, xf, qs, rho_w, cld_evp_eff
1761  REAL*8, INTENT(IN) :: qsd
1762  REAL*8, INTENT(IN) :: cons_h2omw, cons_airmw, cons_alhl, cons_rvap, &
1763 & cons_rgas, cons_pi, cons_cp
1764 !Prognostics
1765  REAL*8, INTENT(INOUT) :: te, qv, ql, qi, f
1766  REAL*8, INTENT(INOUT) :: ted, qvd, qld, qid, fd
1767 !Locals
1768  REAL*8 :: es, radius, k1, k2, teff, qcm, evap, rhx, qc, a_eff, epsilon
1769  REAL*8 :: esd, radiusd, k1d, k2d, teffd, qcmd, evapd, rhxd, qcd
1770  REAL*8, PARAMETER :: k_cond=2.4e-2
1771  REAL*8, PARAMETER :: diffu=2.2e-5
1772  REAL*8, PARAMETER :: nn=50.*1.0e6
1773  INTRINSIC min
1774  epsilon = cons_h2omw/cons_airmw
1775  a_eff = cld_evp_eff
1776 !EVAPORATION OF CLOUD WATER.
1777 ! (100 <-^ convert from mbar to Pa)
1778  esd = (100.*pl*qsd*(epsilon+(1.0-epsilon)*qs)-100.*pl*qs*(1.0-epsilon)&
1779 & *qsd)/(epsilon+(1.0-epsilon)*qs)**2
1780  es = 100.*pl*qs/(epsilon+(1.0-epsilon)*qs)
1781  IF (qv/qs .GT. 1.00) THEN
1782  rhx = 1.00
1783  rhxd = 0.0_8
1784  ELSE
1785  rhxd = (qvd*qs-qv*qsd)/qs**2
1786  rhx = qv/qs
1787  END IF
1788  k1d = -(cons_alhl**2*rho_w*k_cond*cons_rvap*2*te*ted/(k_cond*cons_rvap&
1789 & *te**2)**2)
1790  k1 = cons_alhl**2*rho_w/(k_cond*cons_rvap*te**2)
1791  k2d = (cons_rvap*rho_w*ted*diffu*1000.*es/pl-cons_rvap*te*rho_w*diffu*&
1792 & 1000.*esd/pl)/(diffu*(1000./pl)*es)**2
1793  k2 = cons_rvap*te*rho_w/(diffu*(1000./pl)*es)
1794 !Here DIFFU is given for 1000 mb so 1000./PR accounts for increased diffusivity at lower pressure.
1795  IF (f .GT. 0. .AND. ql .GT. 0.) THEN
1796  qcmd = (qld*f-ql*fd)/f**2
1797  qcm = ql/f
1798  ELSE
1799  qcm = 0.
1800  qcmd = 0.0_8
1801  END IF
1802 qcmd = 0.0_8
1803  CALL ldradius_d(pl, te, ted, qcm, qcmd, nn, rho_w, radius, radiusd, &
1804 & cons_rgas, cons_pi)
1805  IF (rhx .LT. rhcr .AND. radius .GT. 0.0) THEN
1806 ! / (1.00 - RHx)
1807  teffd = (-(rhxd*(k1+k2)*radius**2)-(rhcr-rhx)*((k1d+k2d)*radius**2+(&
1808 & k1+k2)*2*radius*radiusd))/((k1+k2)*radius**2)**2
1809  teff = (rhcr-rhx)/((k1+k2)*radius**2)
1810  ELSE
1811 ! -999.
1812  teff = 0.0
1813  teffd = 0.0_8
1814  END IF
1815  evapd = a_eff*dt*(qld*teff+ql*teffd)
1816  evap = a_eff*ql*dt*teff
1817  IF (evap .GT. ql) THEN
1818  evapd = qld
1819  evap = ql
1820  ELSE
1821  evap = evap
1822  END IF
1823  qcd = qld + qid
1824  qc = ql + qi
1825  IF (qc .GT. 0.) THEN
1826  fd = ((fd*(qc-evap)+f*(qcd-evapd))*qc-f*(qc-evap)*qcd)/qc**2
1827  f = f*(qc-evap)/qc
1828  END IF
1829  qvd = qvd + evapd
1830  qv = qv + evap
1831  qld = qld - evapd
1832  ql = ql - evap
1833  ted = ted - cons_alhl*evapd/cons_cp
1834  te = te - cons_alhl/cons_cp*evap
1835 END SUBROUTINE evap_cnv_d
1836 
1837 ! Differentiation of subl_cnv in forward (tangent) mode:
1838 ! variations of useful results: f qi qv te
1839 ! with respect to varying inputs: f qi ql qs qv te
1840 SUBROUTINE subl_cnv_d(dt, rhcr, pl, te, ted, qv, qvd, ql, qld, qi, qid, &
1841 & f, fd, xf, qs, qsd, rho_w, cld_evp_eff, cons_h2omw, cons_airmw, &
1842 & cons_alhl, cons_rvap, cons_rgas, cons_pi, cons_cp, cons_alhs)
1843  IMPLICIT NONE
1844 !INPUTS
1845  REAL*8, INTENT(IN) :: dt, rhcr, pl, xf, qs, rho_w, cld_evp_eff
1846  REAL*8, INTENT(IN) :: qsd
1847  REAL*8, INTENT(IN) :: cons_h2omw, cons_airmw, cons_alhl, cons_rvap, &
1848 & cons_rgas, cons_pi, cons_cp, cons_alhs
1849 !PROGNOSTIC
1850  REAL*8, INTENT(INOUT) :: te, qv, ql, qi, f
1851  REAL*8, INTENT(INOUT) :: ted, qvd, qld, qid, fd
1852 !LOCALS
1853  REAL*8 :: es, radius, k1, k2, teff, qcm, subl, rhx, qc, a_eff, nn, &
1854 & epsilon
1855  REAL*8 :: esd, radiusd, k1d, k2d, teffd, qcmd, subld, rhxd, qcd
1856  REAL*8, PARAMETER :: k_cond=2.4e-2
1857  REAL*8, PARAMETER :: diffu=2.2e-5
1858  INTRINSIC min
1859  epsilon = cons_h2omw/cons_airmw
1860  a_eff = cld_evp_eff
1861  nn = 5.*1.0e6
1862 ! (100 s <-^ convert from mbar to Pa)
1863  esd = (100.*pl*qsd*(epsilon+(1.0-epsilon)*qs)-100.*pl*qs*(1.0-epsilon)&
1864 & *qsd)/(epsilon+(1.0-epsilon)*qs)**2
1865  es = 100.*pl*qs/(epsilon+(1.0-epsilon)*qs)
1866  IF (qv/qs .GT. 1.00) THEN
1867  rhx = 1.00
1868  rhxd = 0.0_8
1869  ELSE
1870  rhxd = (qvd*qs-qv*qsd)/qs**2
1871  rhx = qv/qs
1872  END IF
1873  k1d = -(cons_alhl**2*rho_w*k_cond*cons_rvap*2*te*ted/(k_cond*cons_rvap&
1874 & *te**2)**2)
1875  k1 = cons_alhl**2*rho_w/(k_cond*cons_rvap*te**2)
1876  k2d = (cons_rvap*rho_w*ted*diffu*1000.*es/pl-cons_rvap*te*rho_w*diffu*&
1877 & 1000.*esd/pl)/(diffu*(1000./pl)*es)**2
1878  k2 = cons_rvap*te*rho_w/(diffu*(1000./pl)*es)
1879 !Here DIFFU is given for 1000 mb so 1000./PR accounts for increased diffusivity at lower pressure.
1880  IF (f .GT. 0. .AND. qi .GT. 0.) THEN
1881  qcmd = (qid*f-qi*fd)/f**2
1882  qcm = qi/f
1883  ELSE
1884  qcm = 0.
1885  qcmd = 0.0_8
1886  END IF
1887 qcmd = 0.0_8
1888  CALL ldradius_d(pl, te, ted, qcm, qcmd, nn, rho_w, radius, radiusd, &
1889 & cons_rgas, cons_pi)
1890  IF (rhx .LT. rhcr .AND. radius .GT. 0.0) THEN
1891 ! / (1.00 - RHx)
1892  teffd = (-(rhxd*(k1+k2)*radius**2)-(rhcr-rhx)*((k1d+k2d)*radius**2+(&
1893 & k1+k2)*2*radius*radiusd))/((k1+k2)*radius**2)**2
1894  teff = (rhcr-rhx)/((k1+k2)*radius**2)
1895  ELSE
1896 ! -999.
1897  teff = 0.0
1898  teffd = 0.0_8
1899  END IF
1900  subld = a_eff*dt*(qid*teff+qi*teffd)
1901  subl = a_eff*qi*dt*teff
1902  IF (subl .GT. qi) THEN
1903  subld = qid
1904  subl = qi
1905  ELSE
1906  subl = subl
1907  END IF
1908  qcd = qld + qid
1909  qc = ql + qi
1910  IF (qc .GT. 0.) THEN
1911  fd = ((fd*(qc-subl)+f*(qcd-subld))*qc-f*(qc-subl)*qcd)/qc**2
1912  f = f*(qc-subl)/qc
1913  END IF
1914  qvd = qvd + subld
1915  qv = qv + subl
1916  qid = qid - subld
1917  qi = qi - subl
1918  ted = ted - cons_alhs*subld/cons_cp
1919  te = te - cons_alhs/cons_cp*subl
1920 END SUBROUTINE subl_cnv_d
1921 
1922 ! Differentiation of ldradius in forward (tangent) mode:
1923 ! variations of useful results: radius
1924 ! with respect to varying inputs: qcl te
1925 SUBROUTINE ldradius_d(pl, te, ted, qcl, qcld, nn, rho_w, radius, radiusd&
1926 & , cons_rgas, cons_pi)
1927  IMPLICIT NONE
1928 !Inputs
1929  REAL*8, INTENT(IN) :: te, pl, nn, qcl, rho_w
1930  REAL*8, INTENT(IN) :: ted, qcld
1931  REAL*8, INTENT(IN) :: cons_rgas, cons_pi
1932 !Outputs
1933  REAL*8, INTENT(OUT) :: radius
1934  REAL*8, INTENT(OUT) :: radiusd
1935  REAL*8 :: pwx1
1936  REAL*8 :: pwx1d
1937 !Equiv. Spherical Cloud Particle Radius in m
1938  pwx1d = (qcld*100.*pl/(cons_rgas*te)-qcl*100.*pl*ted/(cons_rgas*te**2)&
1939 & )/(nn*rho_w*(4./3.)*cons_pi)
1940  pwx1 = qcl*(100.*pl/(cons_rgas*te))/(nn*rho_w*(4./3.)*cons_pi)
1941  IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. 1./3. .EQ. int(1./3.))) &
1942 & THEN
1943  radiusd = pwx1**(1./3.-1)*pwx1d/3.
1944  ELSE IF (pwx1 .EQ. 0.0 .AND. 1./3. .EQ. 1.0) THEN
1945  radiusd = pwx1d
1946  ELSE
1947  radiusd = 0.0
1948  END IF
1949  radius = pwx1**(1./3.)
1950 END SUBROUTINE ldradius_d
1951 
1952 ! Differentiation of autoconversion_ls in forward (tangent) mode:
1953 ! variations of useful results: f qc qp
1954 ! with respect to varying inputs: f qc te
1955 SUBROUTINE autoconversion_ls_d(dt, qc, qcd, qp, qpd, te, ted, pl, f, fd&
1956 & , sundqv2, sundqv3, sundqt1, c_00, lwcrit, dzet)
1957  IMPLICIT NONE
1958 !Inputs
1959  REAL*8, INTENT(IN) :: dt, te, pl, dzet, sundqv2, sundqv3, sundqt1, &
1960 & c_00, lwcrit
1961  REAL*8, INTENT(IN) :: ted
1962 !Prognostic
1963  REAL*8, INTENT(INOUT) :: qc, qp, f
1964  REAL*8, INTENT(INOUT) :: qcd, qpd, fd
1965 !Locals
1966  REAL*8 :: acf0, acf, c00x, iqccrx, f2, f3, rate, dqp, qcm, dqfac
1967  REAL*8 :: c00xd, iqccrxd, f2d, f3d, rated, dqpd, qcmd, dqfacd
1968  INTRINSIC exp
1969  INTRINSIC min
1970  INTRINSIC max
1971  REAL*8 :: arg1
1972  REAL*8 :: arg1d
1973  REAL*8 :: x4
1974  REAL*8 :: x3
1975  REAL*8 :: x2
1976  REAL*8 :: x2d
1977  REAL*8 :: x1
1978  REAL*8 :: x1d
1979  REAL*8 :: x4d
1980 !Zero Locals
1981  acf0 = 0.0
1982  acf = 0.0
1983  c00x = 0.0
1984  iqccrx = 0.0
1985  f2 = 0.0
1986  f3 = 0.0
1987  rate = 0.0
1988  dqp = 0.0
1989  qcm = 0.0
1990  dqfac = 0.0
1991  CALL cons_sundq3_d(te, ted, sundqv2, sundqv3, sundqt1, f2, f2d, f3)
1992  f2d = 0.5*f2d
1993  c00xd = c_00*f3*f2d
1994  c00x = c_00*f2*f3
1995  iqccrxd = f3*f2d/lwcrit
1996  iqccrx = f2*f3/lwcrit
1997  IF (f .GT. 0. .AND. qc .GT. 0.) THEN
1998  qcmd = (qcd*f-qc*fd)/f**2
1999  qcm = qc/f
2000  ELSE
2001  qcm = 0.
2002  qcmd = 0.0_8
2003  END IF
2004  arg1d = -(2*qcm*iqccrx*(qcmd*iqccrx+qcm*iqccrxd))
2005  arg1 = -((qcm*iqccrx)**2)
2006  rated = c00xd*(1.0-exp(arg1)) - c00x*arg1d*exp(arg1)
2007  rate = c00x*(1.0-exp(arg1))
2008 !Temporary kluge until we can figure a better to make thicker low clouds.
2009  f2 = 1.0
2010  f3 = 1.0
2011 !Implement ramps for gradual change in autoconv
2012 !Thicken low high lat clouds
2013  IF (pl .GE. 775. .AND. te .LE. 275.) f3 = 0.2
2014 !F3 = max(-0.016 * PL + 13.4, 0.2)
2015  IF (pl .GE. 825. .AND. te .LE. 282.) f3 = 0.2
2016 !F3 = max(0.11 * TE - 30.02, 0.2)
2017  IF (pl .GE. 775. .AND. pl .LT. 825. .AND. te .LE. 282. .AND. te .GT. &
2018 & 275.) f3 = 0.2
2019 !F3 = min(max(-0.016*PL + 0.11 * TE - 16.85, 0.2),1.)
2020  IF (pl .GE. 825. .AND. te .LE. 275.) f3 = 0.2
2021  IF (pl .LE. 775. .OR. te .GT. 282.) f3 = 1.
2022 !Thin-out low tropical clouds
2023  IF (pl .GE. 950. .AND. te .GE. 285.) THEN
2024  IF (0.2*te - 56 .GT. 2.) THEN
2025  f3 = 2.
2026  f3d = 0.0_8
2027  ELSE
2028  f3d = 0.2*ted
2029  f3 = 0.2*te - 56
2030  END IF
2031  ELSE
2032  f3d = 0.0_8
2033  END IF
2034  IF (pl .GE. 925. .AND. te .GE. 290.) THEN
2035  IF (0.04*pl - 36. .GT. 2.) THEN
2036  f3 = 2.
2037  f3d = 0.0_8
2038  ELSE
2039  f3 = 0.04*pl - 36.
2040  f3d = 0.0_8
2041  END IF
2042  END IF
2043  IF (pl .GE. 925. .AND. pl .LT. 950. .AND. te .GT. 285. .AND. te .LT. &
2044 & 290.) THEN
2045  IF (0.04*pl + 0.2*te - 94. .GT. 2.) THEN
2046  x1 = 2.
2047  x1d = 0.0_8
2048  ELSE
2049  x1d = 0.2*ted
2050  x1 = 0.04*pl + 0.2*te - 94.
2051  END IF
2052  IF (x1 .LT. 1.) THEN
2053  f3 = 1.
2054  f3d = 0.0_8
2055  ELSE
2056  f3d = x1d
2057  f3 = x1
2058  END IF
2059  END IF
2060  IF (pl .GE. 950. .AND. te .GE. 290.) THEN
2061  f3 = 2.
2062  f3d = 0.0_8
2063  END IF
2064  IF (f3 .LT. 0.1) THEN
2065  f3 = 0.1
2066  f3d = 0.0_8
2067  ELSE
2068  f3 = f3
2069  END IF
2070  rated = f3d*rate + f3*rated
2071  rate = f3*rate
2072  dqpd = qcd*(1.0-exp(-(rate*dt))) + qc*dt*rated*exp(-(rate*dt))
2073  dqp = qc*(1.0-exp(-(rate*dt)))
2074  IF (dqp .LT. 0.0) THEN
2075  dqp = 0.0
2076  dqpd = 0.0_8
2077  ELSE
2078  dqp = dqp
2079  END IF
2080 !Wipe-out warm fogs
2081  dqfac = 0.
2082  IF (pl .GE. 975. .AND. te .GE. 280.) THEN
2083  IF (0.2*te - 56. .GT. 1.) THEN
2084  x2 = 1.
2085  x2d = 0.0_8
2086  ELSE
2087  x2d = 0.2*ted
2088  x2 = 0.2*te - 56.
2089  END IF
2090  IF (x2 .LT. 0.) THEN
2091  dqfac = 0.
2092  dqfacd = 0.0_8
2093  ELSE
2094  dqfacd = x2d
2095  dqfac = x2
2096  END IF
2097  ELSE
2098  dqfacd = 0.0_8
2099  END IF
2100  IF (pl .GE. 950. .AND. te .GE. 285.) THEN
2101  IF (0.04*pl - 38. .GT. 1.) THEN
2102  x3 = 1.
2103  ELSE
2104  x3 = 0.04*pl - 38.
2105  END IF
2106  IF (x3 .LT. 0.) THEN
2107  dqfac = 0.
2108  dqfacd = 0.0_8
2109  ELSE
2110  dqfac = x3
2111  dqfacd = 0.0_8
2112  END IF
2113  END IF
2114  IF (pl .GE. 950. .AND. pl .LT. 975. .AND. te .GT. 280. .AND. te .LT. &
2115 & 285.) THEN
2116  IF (0.04*pl + 0.2*te - 95. .GT. 1.) THEN
2117  x4 = 1.
2118  x4d = 0.0_8
2119  ELSE
2120  x4d = 0.2*ted
2121  x4 = 0.04*pl + 0.2*te - 95.
2122  END IF
2123  IF (x4 .LT. 0.) THEN
2124  dqfac = 0.
2125  dqfacd = 0.0_8
2126  ELSE
2127  dqfacd = x4d
2128  dqfac = x4
2129  END IF
2130  END IF
2131  IF (pl .GE. 975. .AND. te .GE. 285.) THEN
2132  dqfac = 1.
2133  dqfacd = 0.0_8
2134  END IF
2135  IF (dqp .LT. dqfac*qc) THEN
2136  dqpd = dqfacd*qc + dqfac*qcd
2137  dqp = dqfac*qc
2138  ELSE
2139  dqp = dqp
2140  END IF
2141  qcd = qcd - dqpd
2142  qc = qc - dqp
2143  qpd = dqpd
2144  qp = qp + dqp
2145 !IF LARGE SCALE THEN
2146  IF (qc + dqp .GT. 0.) THEN
2147  fd = ((qcd*f+qc*fd)*(qc+dqp)-qc*f*(qcd+dqpd))/(qc+dqp)**2
2148  f = qc*f/(qc+dqp)
2149  END IF
2150 END SUBROUTINE autoconversion_ls_d
2151 
2152 ! Differentiation of autoconversion_cnv in forward (tangent) mode:
2153 ! variations of useful results: qc qp
2154 ! with respect to varying inputs: f qc te
2155 SUBROUTINE autoconversion_cnv_d(dt, qc, qcd, qp, qpd, te, ted, pl, f, fd&
2156 & , sundqv2, sundqv3, sundqt1, c_00, lwcrit, dzet)
2157  IMPLICIT NONE
2158 !Inputs
2159  REAL*8, INTENT(IN) :: dt, te, pl, dzet, sundqv2, sundqv3, sundqt1, &
2160 & c_00, lwcrit
2161  REAL*8, INTENT(IN) :: ted
2162 !Prognostic
2163  REAL*8, INTENT(INOUT) :: qc, qp, f
2164  REAL*8, INTENT(INOUT) :: qcd, qpd, fd
2165 !Locals
2166  REAL*8 :: acf0, acf, c00x, iqccrx, f2, f3, rate, dqp, qcm, dqfac
2167  REAL*8 :: c00xd, iqccrxd, f2d, f3d, rated, dqpd, qcmd, dqfacd
2168  INTRINSIC exp
2169  INTRINSIC min
2170  INTRINSIC max
2171  REAL*8 :: arg1
2172  REAL*8 :: arg1d
2173  REAL*8 :: x4
2174  REAL*8 :: x3
2175  REAL*8 :: x2
2176  REAL*8 :: x2d
2177  REAL*8 :: x1
2178  REAL*8 :: x1d
2179  REAL*8 :: x4d
2180 !Zero Locals
2181  acf0 = 0.0
2182  acf = 0.0
2183  c00x = 0.0
2184  iqccrx = 0.0
2185  f2 = 0.0
2186  f3 = 0.0
2187  rate = 0.0
2188  dqp = 0.0
2189  qcm = 0.0
2190  dqfac = 0.0
2191  CALL cons_sundq3_d(te, ted, sundqv2, sundqv3, sundqt1, f2, f2d, f3)
2192  f2d = 0.5*f2d
2193  c00xd = c_00*f3*f2d
2194  c00x = c_00*f2*f3
2195  iqccrxd = f3*f2d/lwcrit
2196  iqccrx = f2*f3/lwcrit
2197  IF (f .GT. 0. .AND. qc .GT. 0.) THEN
2198  qcmd = (qcd*f-qc*fd)/f**2
2199  qcm = qc/f
2200  ELSE
2201  qcm = 0.
2202  qcmd = 0.0_8
2203  END IF
2204  arg1d = -(2*qcm*iqccrx*(qcmd*iqccrx+qcm*iqccrxd))
2205  arg1 = -((qcm*iqccrx)**2)
2206  rated = c00xd*(1.0-exp(arg1)) - c00x*arg1d*exp(arg1)
2207  rate = c00x*(1.0-exp(arg1))
2208 !Temporary kluge until we can figure a better to make thicker low clouds.
2209  f2 = 1.0
2210  f3 = 1.0
2211 !Implement ramps for gradual change in autoconv
2212 !Thicken low high lat clouds
2213  IF (pl .GE. 775. .AND. te .LE. 275.) f3 = 0.2
2214 !F3 = max(-0.016 * PL + 13.4, 0.2)
2215  IF (pl .GE. 825. .AND. te .LE. 282.) f3 = 0.2
2216 !F3 = max(0.11 * TE - 30.02, 0.2)
2217  IF (pl .GE. 775. .AND. pl .LT. 825. .AND. te .LE. 282. .AND. te .GT. &
2218 & 275.) f3 = 0.2
2219 !F3 = min(max(-0.016*PL + 0.11 * TE - 16.85, 0.2),1.)
2220  IF (pl .GE. 825. .AND. te .LE. 275.) f3 = 0.2
2221  IF (pl .LE. 775. .OR. te .GT. 282.) f3 = 1.
2222 !Thin-out low tropical clouds
2223  IF (pl .GE. 950. .AND. te .GE. 285.) THEN
2224  IF (0.2*te - 56 .GT. 2.) THEN
2225  f3 = 2.
2226  f3d = 0.0_8
2227  ELSE
2228  f3d = 0.2*ted
2229  f3 = 0.2*te - 56
2230  END IF
2231  ELSE
2232  f3d = 0.0_8
2233  END IF
2234  IF (pl .GE. 925. .AND. te .GE. 290.) THEN
2235  IF (0.04*pl - 36. .GT. 2.) THEN
2236  f3 = 2.
2237  f3d = 0.0_8
2238  ELSE
2239  f3 = 0.04*pl - 36.
2240  f3d = 0.0_8
2241  END IF
2242  END IF
2243  IF (pl .GE. 925. .AND. pl .LT. 950. .AND. te .GT. 285. .AND. te .LT. &
2244 & 290.) THEN
2245  IF (0.04*pl + 0.2*te - 94. .GT. 2.) THEN
2246  x1 = 2.
2247  x1d = 0.0_8
2248  ELSE
2249  x1d = 0.2*ted
2250  x1 = 0.04*pl + 0.2*te - 94.
2251  END IF
2252  IF (x1 .LT. 1.) THEN
2253  f3 = 1.
2254  f3d = 0.0_8
2255  ELSE
2256  f3d = x1d
2257  f3 = x1
2258  END IF
2259  END IF
2260  IF (pl .GE. 950. .AND. te .GE. 290.) THEN
2261  f3 = 2.
2262  f3d = 0.0_8
2263  END IF
2264  IF (f3 .LT. 0.1) THEN
2265  f3 = 0.1
2266  f3d = 0.0_8
2267  ELSE
2268  f3 = f3
2269  END IF
2270  rated = f3d*rate + f3*rated
2271  rate = f3*rate
2272  dqpd = qcd*(1.0-exp(-(rate*dt))) + qc*dt*rated*exp(-(rate*dt))
2273  dqp = qc*(1.0-exp(-(rate*dt)))
2274  IF (dqp .LT. 0.0) THEN
2275  dqp = 0.0
2276  dqpd = 0.0_8
2277  ELSE
2278  dqp = dqp
2279  END IF
2280 !Wipe-out warm fogs
2281  dqfac = 0.
2282  IF (pl .GE. 975. .AND. te .GE. 280.) THEN
2283  IF (0.2*te - 56. .GT. 1.) THEN
2284  x2 = 1.
2285  x2d = 0.0_8
2286  ELSE
2287  x2d = 0.2*ted
2288  x2 = 0.2*te - 56.
2289  END IF
2290  IF (x2 .LT. 0.) THEN
2291  dqfac = 0.
2292  dqfacd = 0.0_8
2293  ELSE
2294  dqfacd = x2d
2295  dqfac = x2
2296  END IF
2297  ELSE
2298  dqfacd = 0.0_8
2299  END IF
2300  IF (pl .GE. 950. .AND. te .GE. 285.) THEN
2301  IF (0.04*pl - 38. .GT. 1.) THEN
2302  x3 = 1.
2303  ELSE
2304  x3 = 0.04*pl - 38.
2305  END IF
2306  IF (x3 .LT. 0.) THEN
2307  dqfac = 0.
2308  dqfacd = 0.0_8
2309  ELSE
2310  dqfac = x3
2311  dqfacd = 0.0_8
2312  END IF
2313  END IF
2314  IF (pl .GE. 950. .AND. pl .LT. 975. .AND. te .GT. 280. .AND. te .LT. &
2315 & 285.) THEN
2316  IF (0.04*pl + 0.2*te - 95. .GT. 1.) THEN
2317  x4 = 1.
2318  x4d = 0.0_8
2319  ELSE
2320  x4d = 0.2*ted
2321  x4 = 0.04*pl + 0.2*te - 95.
2322  END IF
2323  IF (x4 .LT. 0.) THEN
2324  dqfac = 0.
2325  dqfacd = 0.0_8
2326  ELSE
2327  dqfacd = x4d
2328  dqfac = x4
2329  END IF
2330  END IF
2331  IF (pl .GE. 975. .AND. te .GE. 285.) THEN
2332  dqfac = 1.
2333  dqfacd = 0.0_8
2334  END IF
2335  IF (dqp .LT. dqfac*qc) THEN
2336  dqpd = dqfacd*qc + dqfac*qcd
2337  dqp = dqfac*qc
2338  ELSE
2339  dqp = dqp
2340  END IF
2341  qcd = qcd - dqpd
2342  qc = qc - dqp
2343  qpd = dqpd
2344  qp = qp + dqp
2345 END SUBROUTINE autoconversion_cnv_d
2346 
2347 ! Differentiation of get_ice_fraction in forward (tangent) mode:
2348 ! variations of useful results: icefrct
2349 ! with respect to varying inputs: temp
2350 SUBROUTINE get_ice_fraction_d(temp, tempd, t_ice_all, t_ice_max, &
2351 & icefrpwr, icefrct, icefrctd)
2352  IMPLICIT NONE
2353 !Inputs
2354  REAL*8, INTENT(IN) :: temp, t_ice_all, t_ice_max
2355  REAL*8, INTENT(IN) :: tempd
2356  INTEGER, INTENT(IN) :: icefrpwr
2357 !Outputs
2358  REAL*8, INTENT(OUT) :: icefrct
2359  REAL*8, INTENT(OUT) :: icefrctd
2360  INTRINSIC min
2361  INTRINSIC max
2362  icefrct = 0.00
2363  IF (temp .LE. t_ice_all) THEN
2364  icefrct = 1.000
2365  icefrctd = 0.0_8
2366  ELSE IF (temp .GT. t_ice_all .AND. temp .LE. t_ice_max) THEN
2367  icefrctd = -(tempd/(t_ice_max-t_ice_all))
2368  icefrct = 1.00 - (temp-t_ice_all)/(t_ice_max-t_ice_all)
2369  ELSE
2370  icefrctd = 0.0_8
2371  END IF
2372  IF (icefrct .GT. 1.00) THEN
2373  icefrct = 1.00
2374  icefrctd = 0.0_8
2375  ELSE
2376  icefrct = icefrct
2377  END IF
2378  IF (icefrct .LT. 0.00) THEN
2379  icefrct = 0.00
2380  icefrctd = 0.0_8
2381  ELSE
2382  icefrct = icefrct
2383  END IF
2384  IF (icefrct .GT. 0.0 .OR. (icefrct .LT. 0.0 .AND. icefrpwr .EQ. int(&
2385 & icefrpwr))) THEN
2386  icefrctd = icefrpwr*icefrct**(icefrpwr-1)*icefrctd
2387  ELSE IF (icefrct .EQ. 0.0 .AND. icefrpwr .EQ. 1.0) THEN
2388  icefrctd = icefrctd
2389  ELSE
2390  icefrctd = 0.0
2391  END IF
2392  icefrct = icefrct**icefrpwr
2393 END SUBROUTINE get_ice_fraction_d
2394 
2395 ! Differentiation of cons_sundq3 in forward (tangent) mode:
2396 ! variations of useful results: f2
2397 ! with respect to varying inputs: temp
2398 SUBROUTINE cons_sundq3_d(temp, tempd, rate2, rate3, te1, f2, f2d, f3)
2399  IMPLICIT NONE
2400 !Inputs
2401  REAL*8, INTENT(IN) :: rate2, rate3, te1, temp
2402  REAL*8, INTENT(IN) :: tempd
2403 !Outputs
2404  REAL*8, INTENT(OUT) :: f2, f3
2405  REAL*8, INTENT(OUT) :: f2d
2406 !Locals
2407  REAL*8, PARAMETER :: te0=273.
2408  REAL*8, PARAMETER :: te2=200.
2409  REAL*8 :: jump1
2410  INTRINSIC abs
2411  INTRINSIC min
2412  REAL*8 :: abs0
2413  jump1 = (rate2-1.0)/(te0-te1)**0.333
2414 !Ice - phase treatment
2415  IF (temp .GE. te0) THEN
2416  f2 = 1.0
2417  f3 = 1.0
2418  END IF
2419  IF (temp .GE. te1 .AND. temp .LT. te0) THEN
2420  IF (te0 - temp .GE. 0.) THEN
2421  abs0 = te0 - temp
2422  ELSE
2423  abs0 = -(te0-temp)
2424  END IF
2425  IF (abs0 .GT. 0.0) THEN
2426 !Linearisation security
2427  f2d = -(jump1*0.3333*(te0-temp)**(-0.6667)*tempd)
2428  f2 = 1.0 + jump1*(te0-temp)**0.3333
2429  ELSE
2430  f2 = 1.0
2431  f2d = 0.0_8
2432  END IF
2433  f3 = 1.0
2434  ELSE
2435  f2d = 0.0_8
2436  END IF
2437  IF (temp .LT. te1) THEN
2438  f2d = (-((rate3-rate2)*tempd))/(te1-te2)
2439  f2 = rate2 + (rate3-rate2)*(te1-temp)/(te1-te2)
2440  f3 = 1.0
2441  END IF
2442  IF (f2 .GT. 27.0) THEN
2443  f2 = 27.0
2444  f2d = 0.0_8
2445  ELSE
2446  f2 = f2
2447  END IF
2448 END SUBROUTINE cons_sundq3_d
2449 
2450 ! Differentiation of cons_microphys in forward (tangent) mode:
2451 ! variations of useful results: aa bb
2452 ! with respect to varying inputs: temp q_sat alhx3
2453 SUBROUTINE cons_microphys_d(temp, tempd, pr, q_sat, q_satd, aa, aad, bb&
2454 & , bbd, cons_h2omw, cons_airmw, cons_rvap, alhx3, alhx3d)
2455  IMPLICIT NONE
2456 !Inputs
2457  REAL*8, INTENT(IN) :: temp, q_sat, pr, alhx3
2458  REAL*8, INTENT(IN) :: tempd, q_satd, alhx3d
2459  REAL*8, INTENT(IN) :: cons_h2omw, cons_airmw, cons_rvap
2460 !Outputs
2461  REAL*8, INTENT(OUT) :: aa, bb
2462  REAL*8, INTENT(OUT) :: aad, bbd
2463 !Locals
2464  REAL*8, PARAMETER :: k_cond=2.4e-2
2465  REAL*8, PARAMETER :: diffu=2.2e-5
2466  REAL*8 :: e_sat, epsi
2467  REAL*8 :: e_satd
2468  epsi = cons_h2omw/cons_airmw
2469 ! (100 converts from mbar to Pa)
2470  e_satd = (100.*pr*q_satd*(epsi+(1.0-epsi)*q_sat)-100.*pr*q_sat*(1.0-&
2471 & epsi)*q_satd)/(epsi+(1.0-epsi)*q_sat)**2
2472  e_sat = 100.*pr*q_sat/(epsi+(1.0-epsi)*q_sat)
2473  aad = (2*alhx3*alhx3d*k_cond*cons_rvap*temp**2-alhx3**2*k_cond*&
2474 & cons_rvap*2*temp*tempd)/(k_cond*cons_rvap*temp**2)**2
2475  aa = alhx3**2/(k_cond*cons_rvap*temp**2)
2476  bbd = (cons_rvap*tempd*diffu*1000.*e_sat/pr-cons_rvap*temp*diffu*1000.&
2477 & *e_satd/pr)/(diffu*(1000./pr)*e_sat)**2
2478  bb = cons_rvap*temp/(diffu*(1000./pr)*e_sat)
2479 END SUBROUTINE cons_microphys_d
2480 
2481 ! Differentiation of cons_alhx in forward (tangent) mode:
2482 ! variations of useful results: alhx3
2483 ! with respect to varying inputs: t alhx3
2484 SUBROUTINE cons_alhx_d(t, td, alhx3, alhx3d, t_ice_max, t_ice_all, &
2485 & cons_alhs, cons_alhl)
2486  IMPLICIT NONE
2487 !Inputs
2488  REAL*8, INTENT(IN) :: t, t_ice_max, t_ice_all
2489  REAL*8, INTENT(IN) :: td
2490  REAL*8, INTENT(IN) :: cons_alhs, cons_alhl
2491 !Outputs
2492  REAL*8, INTENT(OUT) :: alhx3
2493  REAL*8, INTENT(OUT) :: alhx3d
2494  IF (t .LT. t_ice_all) THEN
2495  alhx3 = cons_alhs
2496  alhx3d = 0.0_8
2497  END IF
2498  IF (t .GT. t_ice_max) THEN
2499  alhx3 = cons_alhl
2500  alhx3d = 0.0_8
2501  END IF
2502  IF (t .LE. t_ice_max .AND. t .GE. t_ice_all) THEN
2503  alhx3d = (cons_alhl-cons_alhs)*td/(t_ice_max-t_ice_all)
2504  alhx3 = cons_alhs + (cons_alhl-cons_alhs)*(t-t_ice_all)/(t_ice_max-&
2505 & t_ice_all)
2506  END IF
2507 END SUBROUTINE cons_alhx_d
2508 
2509 ! Differentiation of ice_settlefall_cnv in forward (tangent) mode:
2510 ! variations of useful results: qi qp
2511 ! with respect to varying inputs: f qi dz te
2512 SUBROUTINE ice_settlefall_cnv_d(wxr, qi, qid, pl, te, ted, f, fd, &
2513 & cons_rgas, khu, khl, k, dt, dz, dzd, qp, qpd, anv_icefall_c)
2514  IMPLICIT NONE
2515 !Inputs
2516  REAL*8, INTENT(IN) :: wxr, pl, te, dz, dt, anv_icefall_c
2517  REAL*8, INTENT(IN) :: ted, dzd
2518  REAL*8, INTENT(IN) :: cons_rgas
2519  INTEGER, INTENT(IN) :: khu, khl, k
2520  REAL*8, INTENT(INOUT) :: qi, f, qp
2521  REAL*8, INTENT(INOUT) :: qid, fd, qpd
2522 !Locals
2523  REAL*8 :: rho, xim, lxim, qixp, vf
2524  REAL*8 :: rhod, ximd, lximd, qixpd, vfd
2525  INTRINSIC log10
2526  INTRINSIC max
2527  INTRINSIC min
2528  REAL*8 :: pwx1
2529  REAL*8 :: pwr1
2530  REAL*8 :: max1
2531 ! 1000 TAKES TO g m^-3 ; 100 takes mb TO Pa
2532  rhod = -(1000.*100.*pl*cons_rgas*ted/(cons_rgas*te)**2)
2533  rho = 1000.*100.*pl/(cons_rgas*te)
2534  IF (f .GT. 0. .AND. qi .GT. 0.) THEN
2535  ximd = (qid*f-qi*fd)*rho/f**2 + qi*rhod/f
2536  xim = qi/f*rho
2537  ELSE
2538  xim = 0.
2539  ximd = 0.0_8
2540  END IF
2541  IF (xim .GT. 0.) THEN
2542  lximd = ximd/(xim*log(10.0))
2543  lxim = log10(xim)
2544  ELSE
2545  lxim = 0.0
2546  lximd = 0.0_8
2547  END IF
2548  vfd = 53.2*lximd + 5.5*2*lxim*lximd
2549  vf = 128.6 + 53.2*lxim + 5.5*lxim**2
2550 !VF = VF*100./MAX(PL,10.) ! Reduce/increase fall speeds for high/low pressure (NOT in LC98!!! )
2551 ! Assume unmodified they represent situation at 100 mb
2552  IF (wxr .GT. 0.) THEN
2553  IF (pl .LT. 10.) THEN
2554  max1 = 10.
2555  ELSE
2556  max1 = pl
2557  END IF
2558  pwx1 = 100./max1
2559  pwr1 = pwx1**wxr
2560  vfd = pwr1*vfd
2561  vf = vf*pwr1
2562  END IF
2563  vfd = vfd/100.
2564  vf = vf/100.
2565  IF (khu .GT. 0 .AND. khl .GT. 0) THEN
2566  IF (k - 1 .GE. khu .AND. k - 1 .LE. khl) THEN
2567  vfd = 0.01*vfd
2568  vf = 0.01*vf
2569  END IF
2570  END IF
2571  vfd = anv_icefall_c*vfd
2572  vf = anv_icefall_c*vf
2573  qixp = 0.0
2574  qixpd = qid*vf*dt/dz + qi*(dt*vfd*dz-vf*dt*dzd)/dz**2
2575  qixp = qi*(vf*dt/dz)
2576  IF (qixp .GT. qi) THEN
2577  qixpd = qid
2578  qixp = qi
2579  ELSE
2580  qixp = qixp
2581  END IF
2582  IF (qixp .LT. 0.0) THEN
2583  qixp = 0.0
2584  qixpd = 0.0_8
2585  ELSE
2586  qixp = qixp
2587  END IF
2588  qpd = qixpd
2589  qp = qp + qixp
2590  qid = qid - qixpd
2591  qi = qi - qixp
2592 END SUBROUTINE ice_settlefall_cnv_d
2593 
2594 ! Differentiation of ice_settlefall_ls in forward (tangent) mode:
2595 ! variations of useful results: f qi qp
2596 ! with respect to varying inputs: f qi dz te
2597 SUBROUTINE ice_settlefall_ls_d(wxr, qi, qid, pl, te, ted, f, fd, &
2598 & cons_rgas, khu, khl, k, dt, dz, dzd, qp, qpd, ls_icefall_c)
2599  IMPLICIT NONE
2600 !Inputs
2601  REAL*8, INTENT(IN) :: wxr, pl, te, dz, dt, ls_icefall_c
2602  REAL*8, INTENT(IN) :: ted, dzd
2603  REAL*8, INTENT(IN) :: cons_rgas
2604  INTEGER, INTENT(IN) :: khu, khl, k
2605  REAL*8, INTENT(INOUT) :: qi, f, qp
2606  REAL*8, INTENT(INOUT) :: qid, fd, qpd
2607 !Locals
2608  REAL*8 :: rho, xim, lxim, qixp, vf
2609  REAL*8 :: rhod, ximd, qixpd, vfd
2610  INTRINSIC log10
2611  INTRINSIC abs
2612  INTRINSIC max
2613  INTRINSIC min
2614  REAL*8 :: pwx1
2615  REAL*8 :: pwr1
2616  REAL*8 :: abs0
2617  REAL*8 :: max1
2618 ! 1000 TAKES TO g m^-3 ; 100 takes mb TO Pa
2619  rhod = -(1000.*100.*pl*cons_rgas*ted/(cons_rgas*te)**2)
2620  rho = 1000.*100.*pl/(cons_rgas*te)
2621  IF (f .GT. 0. .AND. qi .GT. 0.) THEN
2622  ximd = (qid*f-qi*fd)*rho/f**2 + qi*rhod/f
2623  xim = qi/f*rho
2624  ELSE
2625  xim = 0.
2626  ximd = 0.0_8
2627  END IF
2628  IF (xim .GT. 0.) THEN
2629  lxim = log10(xim)
2630  ELSE
2631  lxim = 0.0
2632  END IF
2633  IF (xim .GE. 0.) THEN
2634  abs0 = xim
2635  ELSE
2636  abs0 = -xim
2637  END IF
2638  IF (abs0 .GT. 0.0) THEN
2639 !Linearisation security
2640  vfd = 109.0*0.16*xim**(-0.84)*ximd
2641  vf = 109.0*xim**0.16
2642  ELSE
2643  vf = 0.0
2644  vfd = 0.0_8
2645  END IF
2646 !VF = VF*100./MAX(PL,10.) ! Reduce/increase fall speeds for high/low pressure (NOT in LC98!!! )
2647 ! Assume unmodified they represent situation at 100 mb
2648  IF (wxr .GT. 0.) THEN
2649  IF (pl .LT. 10.) THEN
2650  max1 = 10.
2651  ELSE
2652  max1 = pl
2653  END IF
2654  pwx1 = 100./max1
2655  pwr1 = pwx1**wxr
2656  vfd = pwr1*vfd
2657  vf = vf*pwr1
2658  END IF
2659  vfd = vfd/100.
2660  vf = vf/100.
2661  IF (khu .GT. 0 .AND. khl .GT. 0) THEN
2662  IF (k - 1 .GE. khu .AND. k - 1 .LE. khl) THEN
2663  vfd = 0.01*vfd
2664  vf = 0.01*vf
2665  END IF
2666  END IF
2667  vfd = ls_icefall_c*vfd
2668  vf = ls_icefall_c*vf
2669  qixp = 0.0
2670  qixpd = qid*vf*dt/dz + qi*(dt*vfd*dz-vf*dt*dzd)/dz**2
2671  qixp = qi*(vf*dt/dz)
2672  IF (qixp .GT. qi) THEN
2673  qixpd = qid
2674  qixp = qi
2675  ELSE
2676  qixp = qixp
2677  END IF
2678  IF (qixp .LT. 0.0) THEN
2679  qixp = 0.0
2680  qixpd = 0.0_8
2681  ELSE
2682  qixp = qixp
2683  END IF
2684  qpd = qixpd
2685  qp = qp + qixp
2686  qid = qid - qixpd
2687  qi = qi - qixp
2688  IF (qi + qixp .GT. 0.) THEN
2689  fd = ((qid*f+qi*fd)*(qi+qixp)-qi*f*(qid+qixpd))/(qi+qixp)**2
2690  f = qi*f/(qi+qixp)
2691  END IF
2692 END SUBROUTINE ice_settlefall_ls_d
2693 
2694 ! Differentiation of precipandevap in forward (tangent) mode:
2695 ! variations of useful results: evap_dd_above_out qv subl_dd_above_out
2696 ! qcl pfi_above_out pfl_above_out te
2697 ! with respect to varying inputs: aa area pfl_above_in qv pfi_above_in
2698 ! bb evap_dd_above_in qcl qpi qpl subl_dd_above_in
2699 ! dze qddf3 te
2700 SUBROUTINE precipandevap_d(k, ktop, lm, dt, frland, rhcr3, qpl, qpld, &
2701 & qpi, qpid, qcl, qcld, qci, te, ted, qv, qvd, mass, imass, pl, dze, &
2702 & dzed, qddf3, qddf3d, aa, aad, bb, bbd, area, aread, pfl_above_in, &
2703 & pfl_above_ind, pfl_above_out, pfl_above_outd, pfi_above_in, &
2704 & pfi_above_ind, pfi_above_out, pfi_above_outd, evap_dd_above_in, &
2705 & evap_dd_above_ind, evap_dd_above_out, evap_dd_above_outd, &
2706 & subl_dd_above_in, subl_dd_above_ind, subl_dd_above_out, &
2707 & subl_dd_above_outd, envfc, ddrfc, cons_alhf, cons_alhs, cons_alhl, &
2708 & cons_cp, cons_tice, cons_h2omw, cons_airmw, revap_off_p, c_acc, c_ev_r&
2709 & , c_ev_s, rho_w, estblx)
2710  IMPLICIT NONE
2711 !Inputs
2712  INTEGER, INTENT(IN) :: k, lm, ktop
2713  REAL*8, INTENT(IN) :: dt, mass, imass, pl, aa, bb, rhcr3, dze, qddf3, &
2714 & area, frland, envfc, ddrfc
2715  REAL*8, INTENT(IN) :: aad, bbd, dzed, qddf3d, aread
2716  REAL*8, INTENT(IN) :: cons_alhf, cons_alhs, cons_alhl, cons_cp, &
2717 & cons_tice, cons_h2omw, cons_airmw
2718  REAL*8, INTENT(IN) :: revap_off_p
2719  REAL*8, INTENT(IN) :: c_acc, c_ev_r, c_ev_s, rho_w
2720  REAL*8, INTENT(IN) :: estblx(:)
2721 !Prognostics
2722  REAL*8, INTENT(INOUT) :: qv, qpl, qpi, qcl, qci, te
2723  REAL*8, INTENT(INOUT) :: qvd, qpld, qpid, qcld, ted
2724  REAL*8, INTENT(INOUT) :: pfl_above_in, pfl_above_out, pfi_above_in, &
2725 & pfi_above_out
2726  REAL*8, INTENT(INOUT) :: pfl_above_ind, pfl_above_outd, pfi_above_ind&
2727 & , pfi_above_outd
2728  REAL*8, INTENT(INOUT) :: evap_dd_above_in, evap_dd_above_out, &
2729 & subl_dd_above_in, subl_dd_above_out
2730  REAL*8, INTENT(INOUT) :: evap_dd_above_ind, evap_dd_above_outd, &
2731 & subl_dd_above_ind, subl_dd_above_outd
2732 !Locals
2733  INTEGER :: ns, nsmx, itr, l
2734  REAL*8 :: pfi, pfl, qs, dqs, envfrac, tko, qko, qstko, dqstko, rh_box&
2735 & , t_ed, qplko, qpiko
2736  REAL*8 :: pfid, pfld, qsd, dqsd, tkod, qkod, qstkod, dqstkod, rh_boxd&
2737 & , t_edd
2738  REAL*8 :: ifactor, rainrat0, snowrat0, fallrn, fallsn, vesn, vern, &
2739 & nrain, nsnow, efactor
2740  REAL*8 :: ifactord, rainrat0d, snowrat0d, fallrnd, fallsnd, vesnd, &
2741 & vernd, efactord
2742  REAL*8 :: tinlayerrn, diamrn, droprad, tinlayersn, diamsn, flakrad
2743  REAL*8 :: tinlayerrnd, diamrnd, dropradd, tinlayersnd, diamsnd, &
2744 & flakradd
2745  REAL*8 :: evap, subl, accr, mltfrz, evapx, sublx, evap_dd, subl_dd, &
2746 & ddfract, landseaf
2747  REAL*8 :: evapd, subld, accrd, mltfrzd, evap_ddd, subl_ddd
2748  REAL*8 :: tau_frz, tau_mlt
2749 !m/s
2750  REAL*8, PARAMETER :: trmv_l=1.0
2751  LOGICAL, PARAMETER :: taneff=.false.
2752 !Fraction of precip falling through "environment" vs through cloud
2753  REAL*8, PARAMETER :: b_sub=1.00
2754  INTRINSIC max
2755  INTRINSIC min
2756  INTRINSIC exp
2757  REAL*8 :: arg1
2758  REAL*8 :: arg1d
2759  envfrac = envfc
2760  IF (area .GT. 0.) THEN
2761  ifactord = -(aread/area**2)
2762  ifactor = 1./area
2763  ELSE
2764  ifactor = 1.00
2765  ifactord = 0.0_8
2766  END IF
2767  IF (ifactor .LT. 1.) THEN
2768  ifactor = 1.
2769  ifactord = 0.0_8
2770  ELSE
2771  ifactor = ifactor
2772  END IF
2773 !Start at top of precip column:
2774 !
2775 ! a) Accrete
2776 ! b) Evaporate/Sublimate
2777 ! c) Rain/Snow-out to next level down
2778 ! d) return to (a)
2779 !Update saturated humidity
2780  CALL dqsats_bac_d(dqs, dqsd, qs, qsd, te, ted, pl, estblx, cons_h2omw&
2781 & , cons_airmw)
2782  ddfract = ddrfc
2783  IF (k .EQ. ktop) THEN
2784  pfld = mass*qpld
2785  pfl = qpl*mass
2786  pfid = mass*qpid
2787  pfi = qpi*mass
2788  evap_dd = 0.
2789  subl_dd = 0.
2790  evap_ddd = 0.0_8
2791  subl_ddd = 0.0_8
2792  ELSE
2793  qpld = qpld + imass*pfl_above_ind
2794  qpl = qpl + pfl_above_in*imass
2795  pfl = 0.00
2796  qpid = qpid + imass*pfi_above_ind
2797  qpi = qpi + pfi_above_in*imass
2798  pfi = 0.00
2799  accrd = b_sub*c_acc*mass*(qpld*qcl+qpl*qcld)
2800  accr = b_sub*c_acc*(qpl*mass)*qcl
2801  IF (accr .GT. qcl) THEN
2802  accrd = qcld
2803  accr = qcl
2804  ELSE
2805  accr = accr
2806  END IF
2807  qpld = qpld + accrd
2808  qpl = qpl + accr
2809  qcld = qcld - accrd
2810  qcl = qcl - accr
2811 !Accretion of liquid condensate by falling ice/snow
2812  accrd = b_sub*c_acc*mass*(qpid*qcl+qpi*qcld)
2813  accr = b_sub*c_acc*(qpi*mass)*qcl
2814  IF (accr .GT. qcl) THEN
2815  accrd = qcld
2816  accr = qcl
2817  ELSE
2818  accr = accr
2819  END IF
2820  qpid = qpid + accrd
2821  qpi = qpi + accr
2822  qcld = qcld - accrd
2823  qcl = qcl - accr
2824 !! Liquid freezes when accreted by snow
2825  ted = ted + cons_alhf*accrd/cons_cp
2826  te = te + cons_alhf*accr/cons_cp
2827  rainrat0d = mass*(ifactord*qpl+ifactor*qpld)/dt
2828  rainrat0 = ifactor*qpl*mass/dt
2829  snowrat0d = mass*(ifactord*qpi+ifactor*qpid)/dt
2830  snowrat0 = ifactor*qpi*mass/dt
2831  CALL marshpalm_d(rainrat0, rainrat0d, pl, diamrn, diamrnd, nrain, &
2832 & fallrn, fallrnd, vern, vernd)
2833  CALL marshpalm_d(snowrat0, snowrat0d, pl, diamsn, diamsnd, nsnow, &
2834 & fallsn, fallsnd, vesn, vesnd)
2835  tinlayerrnd = (dzed*(fallrn+0.01)-dze*fallrnd)/(fallrn+0.01)**2
2836  tinlayerrn = dze/(fallrn+0.01)
2837  tinlayersnd = (dzed*(fallsn+0.01)-dze*fallsnd)/(fallsn+0.01)**2
2838  tinlayersn = dze/(fallsn+0.01)
2839 !Melting of Frozen precipitation
2840 ! time scale for freezing (s).
2841  tau_frz = 5000.
2842  mltfrz = 0.0
2843  IF (te .GT. cons_tice .AND. te .LE. cons_tice + 5.) THEN
2844  mltfrzd = ((tinlayersnd*qpi+tinlayersn*qpid)*(te-cons_tice)+&
2845 & tinlayersn*qpi*ted)/tau_frz
2846  mltfrz = tinlayersn*qpi*(te-cons_tice)/tau_frz
2847  IF (qpi .GT. mltfrz) THEN
2848  mltfrz = mltfrz
2849  ELSE
2850  mltfrzd = qpid
2851  mltfrz = qpi
2852  END IF
2853  ted = ted - cons_alhf*mltfrzd/cons_cp
2854  te = te - cons_alhf*mltfrz/cons_cp
2855  qpld = qpld + mltfrzd
2856  qpl = qpl + mltfrz
2857  qpid = qpid - mltfrzd
2858  qpi = qpi - mltfrz
2859  END IF
2860  mltfrz = 0.0
2861  IF (te .GT. cons_tice + 5.) THEN
2862 ! Go Ahead and melt any snow/hail left above 5 C
2863  mltfrzd = qpid
2864  mltfrz = qpi
2865  ted = ted - cons_alhf*mltfrzd/cons_cp
2866  te = te - cons_alhf*mltfrz/cons_cp
2867  qpld = qpld + mltfrzd
2868  qpl = qpl + mltfrz
2869  qpid = qpid - mltfrzd
2870  qpi = qpi - mltfrz
2871  END IF
2872  mltfrz = 0.0
2873  IF (k .GE. lm - 1) THEN
2874  IF (te .GT. cons_tice + 0.) THEN
2875 ! Go Ahead and melt any snow/hail left above 0 C in lowest layers
2876  mltfrzd = qpid
2877  mltfrz = qpi
2878  ted = ted - cons_alhf*mltfrzd/cons_cp
2879  te = te - cons_alhf*mltfrz/cons_cp
2880  qpld = qpld + mltfrzd
2881  qpl = qpl + mltfrz
2882  qpid = qpid - mltfrzd
2883  qpi = qpi - mltfrz
2884  END IF
2885  END IF
2886 !Freezing of liquid precipitation
2887  mltfrz = 0.0
2888  IF (te .LE. cons_tice) THEN
2889  ted = ted + cons_alhf*qpld/cons_cp
2890  te = te + cons_alhf*qpl/cons_cp
2891  qpid = qpld + qpid
2892  qpi = qpl + qpi
2893  mltfrz = qpl
2894  qpl = 0.
2895  qpld = 0.0_8
2896  END IF
2897 !In the exp below, evaporation time scale is determined "microphysically" from temp,
2898 !press, and drop size. In this context C_EV becomes a dimensionless fudge-fraction.
2899 !Also remember that these microphysics are still only for liquid.
2900  qkod = qvd
2901  qko = qv
2902  tkod = ted
2903  tko = te
2904  qplko = qpl
2905  qpiko = qpi
2906 !do itr = 1,1
2907  itr = 1
2908  dqstkod = dqsd
2909  dqstko = dqs
2910  qstkod = qsd + dqstkod*(tko-te) + dqstko*(tkod-ted)
2911  qstko = qs + dqstko*(tko-te)
2912  IF (qstko .LT. 1.0e-7) THEN
2913  qstko = 1.0e-7
2914  qstkod = 0.0_8
2915  ELSE
2916  qstko = qstko
2917  END IF
2918  rh_boxd = (qkod*qstko-qko*qstkod)/qstko**2
2919  rh_box = qko/qstko
2920  qko = qv
2921  tko = te
2922  IF (rh_box .LT. rhcr3) THEN
2923  efactord = (rho_w*(aad+bbd)*(rhcr3-rh_box)+rho_w*(aa+bb)*rh_boxd)/&
2924 & (rhcr3-rh_box)**2
2925  efactor = rho_w*(aa+bb)/(rhcr3-rh_box)
2926  ELSE
2927  efactor = 9.99e9
2928  efactord = 0.0_8
2929  END IF
2930  IF (frland .LT. 0.1) THEN
2931 ! Over Ocean
2932  landseaf = 0.5
2933  ELSE
2934 ! Over Land
2935  landseaf = 0.5
2936  END IF
2937  landseaf = 1.00
2938 !Rain falling
2939  IF (rh_box .LT. rhcr3 .AND. diamrn .GT. 0.00 .AND. pl .GT. 100. &
2940 & .AND. pl .LT. revap_off_p) THEN
2941  dropradd = 0.5*diamrnd
2942  droprad = 0.5*diamrn
2943  t_edd = efactord*droprad**2 + efactor*2*droprad*dropradd
2944  t_ed = efactor*droprad**2
2945  t_edd = t_edd*(1.0+dqstko*cons_alhl/cons_cp) + t_ed*cons_alhl*&
2946 & dqstkod/cons_cp
2947  t_ed = t_ed*(1.0+dqstko*cons_alhl/cons_cp)
2948  arg1d = -((c_ev_r*landseaf*envfrac*(vernd*tinlayerrn+vern*&
2949 & tinlayerrnd)*t_ed-c_ev_r*vern*landseaf*envfrac*tinlayerrn*t_edd)&
2950 & /t_ed**2)
2951  arg1 = -(c_ev_r*vern*landseaf*envfrac*tinlayerrn/t_ed)
2952  evapd = qpld*(1.0-exp(arg1)) - qpl*arg1d*exp(arg1)
2953  evap = qpl*(1.0-exp(arg1))
2954  ELSE
2955  evap = 0.0
2956  evapd = 0.0_8
2957  END IF
2958 !Snow falling
2959  IF (rh_box .LT. rhcr3 .AND. diamsn .GT. 0.00 .AND. pl .GT. 100. &
2960 & .AND. pl .LT. revap_off_p) THEN
2961  flakradd = 0.5*diamsnd
2962  flakrad = 0.5*diamsn
2963  t_edd = efactord*flakrad**2 + efactor*2*flakrad*flakradd
2964  t_ed = efactor*flakrad**2
2965  t_edd = t_edd*(1.0+dqstko*cons_alhs/cons_cp) + t_ed*cons_alhs*&
2966 & dqstkod/cons_cp
2967  t_ed = t_ed*(1.0+dqstko*cons_alhs/cons_cp)
2968  arg1d = -((c_ev_s*landseaf*envfrac*(vesnd*tinlayersn+vesn*&
2969 & tinlayersnd)*t_ed-c_ev_s*vesn*landseaf*envfrac*tinlayersn*t_edd)&
2970 & /t_ed**2)
2971  arg1 = -(c_ev_s*vesn*landseaf*envfrac*tinlayersn/t_ed)
2972  subld = qpid*(1.0-exp(arg1)) - qpi*arg1d*exp(arg1)
2973  subl = qpi*(1.0-exp(arg1))
2974  ELSE
2975  subl = 0.0
2976  subld = 0.0_8
2977  END IF
2978 !if (itr == 1) then
2979 ! EVAPx = EVAP
2980 ! SUBLx = SUBL
2981 !else
2982 ! EVAP = (EVAP+EVAPx) /2.0
2983 ! SUBL = (SUBL+SUBLx) /2.0
2984 !endif
2985  qko = qv + evap + subl
2986  tko = te - evap*cons_alhl/cons_cp - subl*cons_alhs/cons_cp
2987 !enddo
2988  qpid = qpid - subld
2989  qpi = qpi - subl
2990  qpld = qpld - evapd
2991  qpl = qpl - evap
2992 !Put some re-evap/re-subl precip in to a \quote{downdraft} to be applied later
2993  evap_ddd = evap_dd_above_ind + ddfract*mass*evapd
2994  evap_dd = evap_dd_above_in + ddfract*evap*mass
2995  evapd = evapd - ddfract*evapd
2996  evap = evap - ddfract*evap
2997  subl_ddd = subl_dd_above_ind + ddfract*mass*subld
2998  subl_dd = subl_dd_above_in + ddfract*subl*mass
2999  subld = subld - ddfract*subld
3000  subl = subl - ddfract*subl
3001  qvd = qvd + evapd + subld
3002  qv = qv + evap + subl
3003  ted = ted - cons_alhl*evapd/cons_cp - cons_alhs*subld/cons_cp
3004  te = te - evap*cons_alhl/cons_cp - subl*cons_alhs/cons_cp
3005  pfld = mass*qpld
3006  pfl = qpl*mass
3007  pfid = mass*qpid
3008  pfi = qpi*mass
3009  END IF
3010  evapd = (qddf3d*evap_dd+qddf3*evap_ddd)/mass
3011  evap = qddf3*evap_dd/mass
3012  subld = (qddf3d*subl_dd+qddf3*subl_ddd)/mass
3013  subl = qddf3*subl_dd/mass
3014  qvd = qvd + evapd + subld
3015  qv = qv + evap + subl
3016  ted = ted - cons_alhl*evapd/cons_cp - cons_alhs*subld/cons_cp
3017  te = te - evap*cons_alhl/cons_cp - subl*cons_alhs/cons_cp
3018  qpi = 0.
3019  qpl = 0.
3020  pfl_above_outd = pfld
3021  pfl_above_out = pfl
3022  pfi_above_outd = pfid
3023  pfi_above_out = pfi
3024  evap_dd_above_outd = evap_ddd
3025  evap_dd_above_out = evap_dd
3026  subl_dd_above_outd = subl_ddd
3027  subl_dd_above_out = subl_dd
3028 END SUBROUTINE precipandevap_d
3029 
3030 ! Differentiation of marshpalm in forward (tangent) mode:
3031 ! variations of useful results: diam3 w ve
3032 ! with respect to varying inputs: rain
3033 SUBROUTINE marshpalm_d(rain, raind, pr, diam3, diam3d, ntotal, w, wd, ve&
3034 & , ved)
3035  IMPLICIT NONE
3036 !Inputs
3037 ! in kg m^-2 s^-1, mbar
3038  REAL*8, INTENT(IN) :: rain, pr
3039  REAL*8, INTENT(IN) :: raind
3040 !Outputs
3041  REAL*8, INTENT(OUT) :: diam3, ntotal, w, ve
3042  REAL*8, INTENT(OUT) :: diam3d, wd, ved
3043 !Locals
3044  INTEGER :: iqd
3045 !cm^-3
3046  REAL*8, PARAMETER :: n0=0.08
3047  REAL*8 :: rain_day, slopr, diam1
3048  REAL*8 :: rain_dayd
3049  REAL*8 :: rx(8), d3x(8)
3050  REAL*8 :: rxd(8), d3xd(8)
3051  INTRINSIC sqrt
3052  INTRINSIC max
3053  REAL*8 :: result1
3054  rain_day = 0.0
3055  slopr = 0.0
3056  diam1 = 0.0
3057 !Marshall-Palmer sizes at different rain-rates: avg(D^3)
3058 !RX = (/ 0. , 5. , 20. , 80. , 320. , 1280., 5120., 20480. /) ! rain per in mm/day
3059  rxd(1) = 0.0_8
3060  rx(1) = 0.
3061  rxd(2) = 0.0_8
3062  rx(2) = 5.
3063  rxd(3) = 0.0_8
3064  rx(3) = 20.
3065  rxd(4) = 0.0_8
3066  rx(4) = 80.
3067  rxd(5) = 0.0_8
3068  rx(5) = 320.
3069  rxd(6) = 0.0_8
3070  rx(6) = 1280.
3071  rxd(7) = 0.0_8
3072  rx(7) = 5120.
3073  rxd(8) = 0.0_8
3074  rx(8) = 20480.
3075 !D3X= (/ 0.019, 0.032, 0.043, 0.057, 0.076, 0.102, 0.137, 0.183 /)
3076  d3xd(1) = 0.0_8
3077  d3x(1) = 0.019
3078  d3xd(2) = 0.0_8
3079  d3x(2) = 0.032
3080  d3xd(3) = 0.0_8
3081  d3x(3) = 0.043
3082  d3xd(4) = 0.0_8
3083  d3x(4) = 0.057
3084  d3xd(5) = 0.0_8
3085  d3x(5) = 0.076
3086  d3xd(6) = 0.0_8
3087  d3x(6) = 0.102
3088  d3xd(7) = 0.0_8
3089  d3x(7) = 0.137
3090  d3xd(8) = 0.0_8
3091  d3x(8) = 0.183
3092  rain_dayd = 3600.*24.*raind
3093  rain_day = rain*3600.*24.
3094  IF (rain_day .LE. 0.00) THEN
3095  diam1 = 0.00
3096  diam3 = 0.00
3097  ntotal = 0.00
3098  w = 0.00
3099  diam3d = 0.0_8
3100  ELSE
3101  diam3d = 0.0_8
3102  END IF
3103  DO iqd=1,7
3104  IF (rain_day .LE. rx(iqd+1) .AND. rain_day .GT. rx(iqd)) THEN
3105  slopr = (d3x(iqd+1)-d3x(iqd))/(rx(iqd+1)-rx(iqd))
3106  diam3d = slopr*rain_dayd
3107  diam3 = d3x(iqd) + (rain_day-rx(iqd))*slopr
3108  END IF
3109  END DO
3110  IF (rain_day .GE. rx(8)) THEN
3111  diam3 = d3x(8)
3112  diam3d = 0.0_8
3113  END IF
3114  ntotal = 0.019*diam3
3115  diam3d = 0.664*diam3d
3116  diam3 = 0.664*diam3
3117  result1 = sqrt(1000./pr)
3118  wd = result1*2483.8*diam3d
3119  w = (2483.8*diam3+80.)*result1
3120  IF (0.99*w/100. .LT. 1.000) THEN
3121  ve = 1.000
3122  ved = 0.0_8
3123  ELSE
3124  ved = 0.99*wd/100.
3125  ve = 0.99*w/100.
3126  END IF
3127  diam1 = 3.0*diam3
3128  diam1 = diam1/100.
3129  diam3d = diam3d/100.
3130  diam3 = diam3/100.
3131  wd = wd/100.
3132  w = w/100.
3133  ntotal = ntotal*1.0e6
3134 END SUBROUTINE marshpalm_d
3135 
3136 ! Differentiation of dqsat_bac in forward (tangent) mode:
3137 ! variations of useful results: dqsi qssi
3138 ! with respect to varying inputs: temp dqsi qssi
3139 SUBROUTINE dqsat_bac_d(dqsi, dqsid, qssi, qssid, temp, tempd, plo, im, &
3140 & jm, lm, estblx, cons_h2omw, cons_airmw)
3141  IMPLICIT NONE
3142 !Inputs
3143  INTEGER :: im, jm, lm
3144  REAL*8, DIMENSION(im, jm, lm) :: temp, plo
3145  REAL*8, DIMENSION(im, jm, lm) :: tempd
3146  REAL*8 :: estblx(:)
3147  REAL*8 :: cons_h2omw, cons_airmw
3148 !Outputs
3149  REAL*8, DIMENSION(im, jm, lm) :: dqsi, qssi
3150  REAL*8, DIMENSION(im, jm, lm) :: dqsid, qssid
3151 !Locals
3152  REAL*8, PARAMETER :: max_mixing_ratio=1.0
3153  REAL*8 :: esfac
3154  INTEGER :: i, j, k
3155  REAL*8 :: tl, tt, ti, dqsat, qsat, dqq, qq, pl, pp, dd
3156  REAL*8 :: tld, ttd, tid, dqsatd, qsatd, qqd, ddd
3157  INTEGER :: it
3158  INTEGER, PARAMETER :: degsubs=100
3159  REAL*8, PARAMETER :: tmintbl=150.0, tmaxtbl=333.0
3160  INTEGER, PARAMETER :: tablesize=nint(tmaxtbl-tmintbl)*degsubs+1
3161  INTRINSIC nint
3162  INTRINSIC int
3163  esfac = cons_h2omw/cons_airmw
3164  DO k=1,lm
3165  DO j=1,jm
3166  DO i=1,im
3167  tld = tempd(i, j, k)
3168  tl = temp(i, j, k)
3169  pl = plo(i, j, k)
3170  pp = pl*100.0
3171  IF (tl .LE. tmintbl) THEN
3172  ti = tmintbl
3173  tid = 0.0_8
3174  ELSE IF (tl .GE. tmaxtbl - .001) THEN
3175  tid = 0.0_8
3176  ti = tmaxtbl - .001
3177  ELSE
3178  tid = tld
3179  ti = tl
3180  END IF
3181  ttd = degsubs*tid
3182  tt = (ti-tmintbl)*degsubs + 1
3183  it = int(tt)
3184  dqq = estblx(it+1) - estblx(it)
3185  qqd = dqq*ttd
3186  qq = (tt-it)*dqq + estblx(it)
3187  IF (pp .LE. qq) THEN
3188  qsat = max_mixing_ratio
3189  dqsat = 0.0
3190  qsatd = 0.0_8
3191  dqsatd = 0.0_8
3192  ELSE
3193  ddd = -((-((1.0-esfac)*qqd))/(pp-(1.0-esfac)*qq)**2)
3194  dd = 1.0/(pp-(1.0-esfac)*qq)
3195  qsatd = esfac*(qqd*dd+qq*ddd)
3196  qsat = esfac*qq*dd
3197  dqsatd = esfac*degsubs*dqq*pp*(ddd*dd+dd*ddd)
3198  dqsat = esfac*degsubs*dqq*pp*(dd*dd)
3199  END IF
3200  dqsid(i, j, k) = dqsatd
3201  dqsi(i, j, k) = dqsat
3202  qssid(i, j, k) = qsatd
3203  qssi(i, j, k) = qsat
3204  END DO
3205  END DO
3206  END DO
3207 END SUBROUTINE dqsat_bac_d
3208 
3209 ! Differentiation of dqsats_bac in forward (tangent) mode:
3210 ! variations of useful results: dqsi qssi
3211 ! with respect to varying inputs: temp
3212 SUBROUTINE dqsats_bac_d(dqsi, dqsid, qssi, qssid, temp, tempd, plo, &
3213 & estblx, cons_h2omw, cons_airmw)
3214  IMPLICIT NONE
3215 !Inputs
3216  REAL*8 :: temp, plo
3217  REAL*8 :: tempd
3218  REAL*8 :: estblx(:)
3219  REAL*8 :: cons_h2omw, cons_airmw
3220 !Outputs
3221  REAL*8 :: dqsi, qssi
3222  REAL*8 :: dqsid, qssid
3223 !Locals
3224  REAL*8, PARAMETER :: max_mixing_ratio=1.0
3225  REAL*8 :: esfac
3226  REAL*8 :: tl, tt, ti, dqsat, qsat, dqq, qq, pl, pp, dd
3227  REAL*8 :: tld, ttd, tid, dqsatd, qsatd, qqd, ddd
3228  INTEGER :: it
3229  INTEGER, PARAMETER :: degsubs=100
3230  REAL*8, PARAMETER :: tmintbl=150.0, tmaxtbl=333.0
3231  INTEGER, PARAMETER :: tablesize=nint(tmaxtbl-tmintbl)*degsubs+1
3232  INTRINSIC nint
3233  INTRINSIC int
3234  esfac = cons_h2omw/cons_airmw
3235  tld = tempd
3236  tl = temp
3237  pl = plo
3238  pp = pl*100.0
3239  IF (tl .LE. tmintbl) THEN
3240  ti = tmintbl
3241  tid = 0.0_8
3242  ELSE IF (tl .GE. tmaxtbl - .001) THEN
3243  ti = tmaxtbl - .001
3244  tid = 0.0_8
3245  ELSE
3246  tid = tld
3247  ti = tl
3248  END IF
3249  ttd = degsubs*tid
3250  tt = (ti-tmintbl)*degsubs + 1
3251  it = int(tt)
3252  dqq = estblx(it+1) - estblx(it)
3253  qqd = dqq*ttd
3254  qq = (tt-it)*dqq + estblx(it)
3255  IF (pp .LE. qq) THEN
3256  qsat = max_mixing_ratio
3257  dqsat = 0.0
3258  qsatd = 0.0_8
3259  dqsatd = 0.0_8
3260  ELSE
3261  ddd = -((-((1.0-esfac)*qqd))/(pp-(1.0-esfac)*qq)**2)
3262  dd = 1.0/(pp-(1.0-esfac)*qq)
3263  qsatd = esfac*(qqd*dd+qq*ddd)
3264  qsat = esfac*qq*dd
3265  dqsatd = esfac*degsubs*dqq*pp*(ddd*dd+dd*ddd)
3266  dqsat = esfac*degsubs*dqq*pp*(dd*dd)
3267  END IF
3268  dqsid = dqsatd
3269  dqsi = dqsat
3270  qssid = qsatd
3271  qssi = qsat
3272 END SUBROUTINE dqsats_bac_d
3273 
3274 END MODULE cloud_tl
subroutine precipandevap_d(k, ktop, lm, dt, frland, rhcr3, qpl, qpld, qpi, qpid, qcl, qcld, qci, te, ted, qv, qvd, mass, imass, pl, dze, dzed, qddf3, qddf3d, aa, aad, bb, bbd, area, aread, pfl_above_in, pfl_above_ind, pfl_above_out, pfl_above_outd, pfi_above_in, pfi_above_ind, pfi_above_out, pfi_above_outd, evap_dd_above_in, evap_dd_above_ind, evap_dd_above_out, evap_dd_above_outd, subl_dd_above_in, subl_dd_above_ind, subl_dd_above_out, subl_dd_above_outd, envfc, ddrfc, cons_alhf, cons_alhs, cons_alhl, cons_cp, cons_tice, cons_h2omw, cons_airmw, revap_off_p, c_acc, c_ev_r, c_ev_s, rho_w, estblx)
Definition: cloud_tl.F90:2710
subroutine cons_microphys_d(temp, tempd, pr, q_sat, q_satd, aa, aad, bb, bbd, cons_h2omw, cons_airmw, cons_rvap, alhx3, alhx3d)
Definition: cloud_tl.F90:2455
subroutine cons_sundq3_d(temp, tempd, rate2, rate3, te1, f2, f2d, f3)
Definition: cloud_tl.F90:2399
subroutine meltfreeze_d(dt, te, ted, ql, qld, qi, qid, t_ice_all, t_ice_max, icefrpwr, cons_alhl, cons_alhs, cons_cp)
Definition: cloud_tl.F90:993
subroutine dqsat_bac_d(dqsi, dqsid, qssi, qssid, temp, tempd, plo, im, jm, lm, estblx, cons_h2omw, cons_airmw)
Definition: cloud_tl.F90:3141
subroutine dqsats_bac_d(dqsi, dqsid, qssi, qssid, temp, tempd, plo, estblx, cons_h2omw, cons_airmw)
Definition: cloud_tl.F90:3214
subroutine, public ls_cloud_d(dt, alpha, pdfshape, pl, te, ted, qv, qvd, qcl, qcld, qal, qald, qci, qcid, qai, qaid, cf, cfd, af, afd, cons_alhl, cons_alhf, cons_alhs, cons_cp, cons_h2omw, cons_airmw, t_ice_all, t_ice_max, icefrpwr, estblx, cloud_pertmod, dmp)
Definition: cloud_tl.F90:1157
subroutine ice_settlefall_ls_d(wxr, qi, qid, pl, te, ted, f, fd, cons_rgas, khu, khl, k, dt, dz, dzd, qp, qpd, ls_icefall_c)
Definition: cloud_tl.F90:2599
subroutine, public cloud_driver_d(dt, im, jm, lm, th, thd, q, qd, ple, cnv_dqldt, cnv_dqldtd, cnv_mfd, cnv_mfdd, cnv_prc3, cnv_prc3d, cnv_updf, cnv_updfd, qi_ls, qi_lsd, ql_ls, ql_lsd, qi_con, qi_cond, ql_con, ql_cond, cf_ls, cf_lsd, cf_con, cf_cond, frland, physparams, estblx, khu, khl, cons_runiv, cons_kappa, cons_airmw, cons_h2omw, cons_grav, cons_alhl, cons_alhf, cons_pi, cons_rgas, cons_cp, cons_vireps, cons_alhs, cons_tice, cons_rvap, cons_p00, do_moist_physics)
Definition: cloud_tl.F90:30
Definition: cloud.F90:1
subroutine cons_alhx_d(t, td, alhx3, alhx3d, t_ice_max, t_ice_all, cons_alhs, cons_alhl)
Definition: cloud_tl.F90:2486
subroutine, public pdf_width(PP, FRLAND, maxrhcrit, maxrhcritland, turnrhcrit, minrhcrit, pi_0, ALPHA)
Definition: cloud.F90:1046
subroutine marshpalm_d(rain, raind, pr, diam3, diam3d, ntotal, w, wd, ve, ved)
Definition: cloud_tl.F90:3035
subroutine evap_cnv_d(dt, rhcr, pl, te, ted, qv, qvd, ql, qld, qi, qid, f, fd, xf, qs, qsd, rho_w, cld_evp_eff, cons_h2omw, cons_airmw, cons_alhl, cons_rvap, cons_rgas, cons_pi, cons_cp)
Definition: cloud_tl.F90:1758
subroutine convec_src_d(dt, mass, imass, te, ted, qv, qvd, dcf, dcfd, dmf, dmfd, qla, qlad, qia, qiad, af, afd, qs, qsd, cons_alhs, cons_alhl, cons_cp, t_ice_all, t_ice_max, icefrpwr)
Definition: cloud_tl.F90:1063
subroutine ldradius_d(pl, te, ted, qcl, qcld, nn, rho_w, radius, radiusd, cons_rgas, cons_pi)
Definition: cloud_tl.F90:1927
subroutine cloud_tidy_d(qv, qvd, te, ted, qlc, qlcd, qic, qicd, cf, cfd, qla, qlad, qia, qiad, af, afd, cons_alhl, cons_alhs, cons_cp)
Definition: cloud_tl.F90:899
subroutine pdfcondensate_d(flag, qtmean4, qtmean4d, sigmaqt14, sigmaqt14d, sigmaqt24, sigmaqt24d, qstar4, qstar4d, condensate4, condensate4d)
Definition: cloud_tl.F90:1608
subroutine autoconversion_cnv_d(dt, qc, qcd, qp, qpd, te, ted, pl, f, fd, sundqv2, sundqv3, sundqt1, c_00, lwcrit, dzet)
Definition: cloud_tl.F90:2157
#define max(a, b)
Definition: mosaic_util.h:33
subroutine ice_settlefall_cnv_d(wxr, qi, qid, pl, te, ted, f, fd, cons_rgas, khu, khl, k, dt, dz, dzd, qp, qpd, anv_icefall_c)
Definition: cloud_tl.F90:2514
subroutine autoconversion_ls_d(dt, qc, qcd, qp, qpd, te, ted, pl, f, fd, sundqv2, sundqv3, sundqt1, c_00, lwcrit, dzet)
Definition: cloud_tl.F90:1957
subroutine get_ice_fraction_d(temp, tempd, t_ice_all, t_ice_max, icefrpwr, icefrct, icefrctd)
Definition: cloud_tl.F90:2352
#define min(a, b)
Definition: mosaic_util.h:32
subroutine pdffrac_d(flag, qtmean, qtmeand, sigmaqt1, sigmaqt1d, sigmaqt2, sigmaqt2d, qstar, qstard, clfrac, clfracd)
Definition: cloud_tl.F90:1465
subroutine subl_cnv_d(dt, rhcr, pl, te, ted, qv, qvd, ql, qld, qi, qid, f, fd, xf, qs, qsd, rho_w, cld_evp_eff, cons_h2omw, cons_airmw, cons_alhl, cons_rvap, cons_rgas, cons_pi, cons_cp, cons_alhs)
Definition: cloud_tl.F90:1843