GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: phylmd/cv3_cine.F90 Lines: 179 182 98.4 %
Date: 2023-06-30 12:56:34 Branches: 209 216 96.8 %

Line Branch Exec Source
1
2
! $Id: cv3_cine.F90 2416 2015-12-24 11:58:33Z jyg $
3
4
449183
SUBROUTINE cv3_cine(nloc, ncum, nd, icb, inb, pbase, plcl, p, ph, tv, tvp, &
5
144
    cina, cinb, plfc)
6
7
  ! **************************************************************
8
  ! *
9
  ! CV3_CINE                                                    *
10
  ! *
11
  ! *
12
  ! written by   :   Frederique Cheruy                          *
13
  ! vectorization:   Jean-Yves Grandpeix, 19/06/2003, 11.54.43  *
14
  ! modified by :                                               *
15
  ! **************************************************************
16
17
  IMPLICIT NONE
18
19
  include "YOMCST.h"
20
  include "cvthermo.h"
21
  include "cv3param.h"
22
  ! input:
23
  INTEGER ncum, nd, nloc
24
  INTEGER icb(nloc), inb(nloc)
25
  REAL pbase(nloc), plcl(nloc)
26
  REAL p(nloc, nd), ph(nloc, nd+1)
27
  REAL tv(nloc, nd), tvp(nloc, nd)
28
29
  ! output
30
  REAL cina(nloc), cinb(nloc), plfc(nloc)
31
32
  ! local variables
33
  INTEGER il, i, j, k
34
288
  INTEGER itop(nloc), ineg(nloc), ilow(nloc)
35
288
  INTEGER ifst(nloc), isublcl(nloc)
36
288
  LOGICAL lswitch(nloc), lswitch1(nloc), lswitch2(nloc), lswitch3(nloc)
37
288
  LOGICAL exist_lfc(nloc)
38
  REAL dpmax
39
  REAL deltap, dcin
40
288
  REAL buoylcl(nloc), tvplcl(nloc), tvlcl(nloc)
41
288
  REAL p0(nloc)
42
288
  REAL buoyz(nloc), buoy(nloc, nd)
43
44
  ! -------------------------------------------------------------
45
  ! Initialization
46
  ! -------------------------------------------------------------
47
69110
  DO il = 1, ncum
48
68966
    cina(il) = 0.
49
69110
    cinb(il) = 0.
50
  END DO
51
52
  ! --------------------------------------------------------------
53
  ! Recompute buoyancies
54
  ! --------------------------------------------------------------
55
5760
  DO k = 1, nd
56
2695434
    DO il = 1, ncum
57
      ! print*,'tvp tv=',tvp(il,k),tv(il,k)
58
2695290
      buoy(il, k) = tvp(il, k) - tv(il, k)
59
    END DO
60
  END DO
61
  ! ---------------------------------------------------------------
62
63
  ! calcul de la flottabilite a LCL (Buoylcl)
64
  ! ifst = first P-level above lcl
65
  ! isublcl = highest P-level below lcl.
66
  ! ---------------------------------------------------------------
67
68
69110
  DO il = 1, ncum
69
69110
    tvplcl(il) = tvp(il, 1)*(plcl(il)/p(il,1))**(2./7.) !For dry air, R/Cp=2/7
70
  END DO
71
72
69110
  DO il = 1, ncum
73
69110
    IF (plcl(il)>p(il,icb(il))) THEN
74
31040
      ifst(il) = icb(il)
75
31040
      isublcl(il) = icb(il) - 1
76
    ELSE
77
37926
      ifst(il) = icb(il) + 1
78
37926
      isublcl(il) = icb(il)
79
    END IF
80
  END DO
81
82
69110
  DO il = 1, ncum
83
    tvlcl(il) = tv(il, ifst(il)-1) + (tv(il,ifst(il))-tv(il,ifst(il)-1))*( &
84
69110
      plcl(il)-p(il,ifst(il)-1))/(p(il,ifst(il))-p(il,ifst(il)-1))
85
  END DO
86
87
69110
  DO il = 1, ncum
88
69110
    buoylcl(il) = tvplcl(il) - tvlcl(il)
89
  END DO
90
91
  ! ---------------------------------------------------------------
92
  ! premiere couche contenant un  niveau de flotabilite positive
93
  ! et premiere couche contenant un  niveau de flotabilite negative
94
  ! au dessus du niveau de condensation
95
  ! ---------------------------------------------------------------
96
69110
  DO il = 1, ncum
97
68966
    itop(il) = nl - 1
98
68966
    ineg(il) = nl - 1
99
69110
    exist_lfc(il) = .FALSE.
100
  END DO
101
3888
  DO k = nl - 1, 1, -1
102
1797004
    DO il = 1, ncum
103
1796860
      IF (k>=ifst(il)) THEN
104
1449226
        IF (buoy(il,k)>0.) THEN
105
464523
          itop(il) = k
106
464523
          exist_lfc(il) = .TRUE.
107
        ELSE
108
984703
          ineg(il) = k
109
        END IF
110
      END IF
111
    END DO
112
  END DO
113
114
  ! ---------------------------------------------------------------
115
  ! When there is no positive buoyancy level, set Plfc, Cina and Cinb
116
  ! to arbitrary extreme values.
117
  ! ---------------------------------------------------------------
118
69110
  DO il = 1, ncum
119
69110
    IF (.NOT. exist_lfc(il)) THEN
120
4026
      plfc(il) = 1.111
121
4026
      cinb(il) = -1111.
122
4026
      cina(il) = -1112.
123
    END IF
124
  END DO
125
126
127
  ! ---------------------------------------------------------------
128
  ! -- Two cases : BUOYlcl >= 0 and BUOYlcl < 0.
129
  ! ---------------------------------------------------------------
130
131
  ! --------------------
132
  ! -- 1.0 BUOYlcl >=0.
133
  ! --------------------
134
135
  dpmax = 50.
136
69110
  DO il = 1, ncum
137

68966
    lswitch1(il) = buoylcl(il) >= 0. .AND. exist_lfc(il)
138
69110
    lswitch(il) = lswitch1(il)
139
  END DO
140
141
  ! 1.1 No inhibition case
142
  ! ----------------------
143
  ! If buoyancy is positive at LCL and stays positive over a large enough
144
  ! pressure interval (=DPMAX), inhibition is set to zero,
145
146
69110
  DO il = 1, ncum
147
69110
    IF (lswitch(il)) THEN
148
13824
      IF (p(il,ineg(il))<p(il,icb(il))-dpmax) THEN
149
11667
        plfc(il) = plcl(il)
150
11667
        cina(il) = 0.
151
11667
        cinb(il) = 0.
152
      END IF
153
    END IF
154
  END DO
155
156
  ! 1.2 Upper inhibition only case
157
  ! ------------------------------
158
69110
  DO il = 1, ncum
159
68966
    lswitch2(il) = p(il, ineg(il)) >= p(il, icb(il)) - dpmax
160

135919
    lswitch(il) = lswitch1(il) .AND. lswitch2(il)
161
  END DO
162
163
  ! 1.2.1 Recompute itop (=1st layer with positive buoyancy above ineg)
164
  ! -------------------------------------------------------------------
165
166
69110
  DO il = 1, ncum
167
69110
    IF (lswitch(il)) THEN
168
2157
      itop(il) = nl - 1
169
    END IF
170
  END DO
171
172
4032
  DO k = nl, 1, -1
173
1866114
    DO il = 1, ncum
174
1865970
      IF (lswitch(il)) THEN
175

58239
        IF (k>=ineg(il) .AND. buoy(il,k)>0) THEN
176
7385
          itop(il) = k
177
        END IF
178
      END IF
179
    END DO
180
  END DO
181
182
  ! If there is no layer with positive buoyancy above ineg, set Plfc,
183
  ! Cina and Cinb to arbitrary extreme values.
184
69110
  DO il = 1, ncum
185

69110
    IF (lswitch(il) .AND. itop(il) == nl - 1) THEN
186
317
      plfc(il) = 1.121
187
317
      cinb(il) = -1121.
188
317
      cina(il) = -1122.
189
    END IF
190
  END DO
191
192
69110
  DO il = 1, ncum
193
68966
    lswitch3(il) = itop(il) < nl -1
194

136236
    lswitch(il) = lswitch1(il) .AND. lswitch2(il) .AND. lswitch3(il)
195
  END DO
196
197
69110
  DO il = 1, ncum
198
69110
    IF (lswitch(il)) THEN
199
1840
      cinb(il) = 0.
200
201
      ! 1.2.2  Calcul de la pression du niveau de flot. nulle juste au-dessus
202
      ! de LCL
203
      ! ---------------------------------------------------------------------------
204
1840
      IF (ineg(il)>isublcl(il)+1) THEN
205
        ! In order to get P0, one may interpolate linearly buoyancies
206
        ! between P(ineg) and P(ineg-1).
207
        p0(il) = (buoy(il,ineg(il))*p(il,ineg(il)-1)-buoy(il,ineg(il)-1)*p(il,ineg(il)))/ &
208
67
          (buoy(il,ineg(il))-buoy(il,ineg(il)-1))
209
      ELSE
210
        ! In order to get P0, one has to interpolate between P(ineg) and
211
        ! Plcl.
212
        p0(il) = (buoy(il,ineg(il))*plcl(il)-buoylcl(il)*p(il,ineg(il)))/ &
213
1773
          (buoy(il,ineg(il))-buoylcl(il))
214
      END IF
215
    END IF
216
  END DO
217
218
  ! 1.2.3 Computation of PLFC
219
  ! -------------------------
220
69110
  DO il = 1, ncum
221
69110
    IF (lswitch(il)) THEN
222
      plfc(il) = (buoy(il,itop(il))*p(il,itop(il)-1)-buoy(il,itop( &
223
1840
        il)-1)*p(il,itop(il)))/(buoy(il,itop(il))-buoy(il,itop(il)-1))
224
    END IF
225
  END DO
226
227
  ! 1.2.4 Computation of CINA
228
  ! -------------------------
229
230
  ! Upper part of CINA : integral from P(itop-1) to Plfc
231
69110
  DO il = 1, ncum
232
69110
    IF (lswitch(il)) THEN
233
1840
      deltap = p(il, itop(il)-1) - plfc(il)
234
1840
      dcin = rd*buoy(il, itop(il)-1)*deltap/(p(il,itop(il)-1)+plfc(il))
235
1840
      cina(il) = min(0., dcin)
236
    END IF
237
  END DO
238
239
  ! Middle part of CINA : integral from P(ineg) to P(itop-1)
240
4032
  DO k = 1, nl
241
1866114
    DO il = 1, ncum
242
1865970
      IF (lswitch(il)) THEN
243

49680
        IF (k>=ineg(il) .AND. k<=itop(il)-2) THEN
244
199
          deltap = p(il, k) - p(il, k+1)
245
199
          dcin = 0.5*rd*(buoy(il,k)+buoy(il,k+1))*deltap/ph(il, k+1)
246
199
          cina(il) = cina(il) + min(0., dcin)
247
        END IF
248
      END IF
249
    END DO
250
  END DO
251
252
  ! Lower part of CINA : integral from P0 to P(ineg)
253
69110
  DO il = 1, ncum
254
69110
    IF (lswitch(il)) THEN
255
1840
      deltap = p0(il) - p(il, ineg(il))
256
1840
      dcin = rd*buoy(il, ineg(il))*deltap/(p(il,ineg(il))+p0(il))
257
1840
      cina(il) = cina(il) + min(0., dcin)
258
    END IF
259
  END DO
260
261
262
  ! ------------------
263
  ! -- 2.0 BUOYlcl <0.
264
  ! ------------------
265
266
69110
  DO il = 1, ncum
267

68966
    lswitch1(il) = buoylcl(il) < 0. .AND. exist_lfc(il)
268
69110
    lswitch(il) = lswitch1(il)
269
  END DO
270
271
  ! 2.0.1 Premiere  couche ou la flotabilite est negative au dessus du sol
272
  ! ----------------------------------------------------
273
  ! au cas ou elle existe  sinon ilow=1 (nk apres)
274
  ! on suppose que la parcelle part de la premiere couche
275
276
69110
  DO il = 1, ncum
277
69110
    IF (lswitch(il)) THEN
278
51116
      ilow(il) = 1
279
    END IF
280
  END DO
281
282
4032
  DO k = nl, 1, -1
283
1866114
    DO il = 1, ncum
284

1865970
      IF (lswitch(il) .AND. k<=icb(il)-1) THEN
285
223372
        IF (buoy(il,k)<0.) THEN
286
78467
          ilow(il) = k
287
        END IF
288
      END IF
289
    END DO
290
  END DO
291
292
  ! 2.0.2  Calcul de la pression du niveau de flot. nulle sous le nuage
293
  ! ----------------------------------------------------
294
69110
  DO il = 1, ncum
295
69110
    IF (lswitch(il)) THEN
296
51116
      IF (ilow(il)>1) THEN
297
        p0(il) = (buoy(il,ilow(il))*p(il,ilow(il)-1)-buoy(il,ilow( &
298
8038
          il)-1)*p(il,ilow(il)))/(buoy(il,ilow(il))-buoy(il,ilow(il)-1))
299
8038
        buoyz(il) = 0.
300
      ELSE
301
43078
        p0(il) = p(il, 1)
302
43078
        buoyz(il) = buoy(il, 1)
303
      END IF
304
    END IF
305
  END DO
306
307
  ! 2.1. Computation of CINB
308
  ! -----------------------
309
310
69110
  DO il = 1, ncum
311
    lswitch2(il) = (isublcl(il)==1 .AND. ilow(il)==1) .OR. &
312

68966
      (isublcl(il)==ilow(il)-1)
313

138076
    lswitch(il) = lswitch1(il) .AND. lswitch2(il)
314
  END DO
315
  ! c      IF (    (isublcl .EQ. 1 .AND. ilow .EQ. 1)
316
  ! c     $    .OR.(isublcl .EQ. ilow-1)) THEN
317
318
  ! 2.1.1 First case : Plcl just above P0
319
  ! -------------------------------------
320
69110
  DO il = 1, ncum
321
69110
    IF (lswitch(il)) THEN
322
      deltap = p0(il) - plcl(il)
323
      dcin = rd*(buoyz(il)+buoylcl(il))*deltap/(p0(il)+plcl(il))
324
      cinb(il) = min(0., dcin)
325
    END IF
326
  END DO
327
328
69110
  DO il = 1, ncum
329

86960
    lswitch(il) = lswitch1(il) .AND. .NOT. lswitch2(il)
330
  END DO
331
  ! c      ELSE
332
333
  ! 2.1.2 Second case : there is at least one P-level between P0 and Plcl
334
  ! ---------------------------------------------------------------------
335
336
  ! Lower part of CINB : integral from P0 to P(ilow)
337
69110
  DO il = 1, ncum
338
69110
    IF (lswitch(il)) THEN
339
51116
      deltap = p0(il) - p(il, ilow(il))
340
51116
      dcin = rd*(buoyz(il)+buoy(il,ilow(il)))*deltap/(p0(il)+p(il,ilow(il)))
341
51116
      cinb(il) = min(0., dcin)
342
    END IF
343
  END DO
344
345
346
  ! Middle part of CINB : integral from P(ilow) to P(isublcl)
347
  ! c      DO k = ilow,isublcl-1
348
4032
  DO k = 1, nl
349
1866114
    DO il = 1, ncum
350

1865970
      IF (lswitch(il) .AND. k>=ilow(il) .AND. k<=isublcl(il)-1) THEN
351
187598
        deltap = p(il, k) - p(il, k+1)
352
187598
        dcin = 0.5*rd*(buoy(il,k)+buoy(il,k+1))*deltap/ph(il, k+1)
353
187598
        cinb(il) = cinb(il) + min(0., dcin)
354
      END IF
355
    END DO
356
  END DO
357
358
  ! Upper part of CINB : integral from P(isublcl) to Plcl
359
69110
  DO il = 1, ncum
360
69110
    IF (lswitch(il)) THEN
361
51116
      deltap = p(il, isublcl(il)) - plcl(il)
362
      dcin = rd*(buoy(il,isublcl(il))+buoylcl(il))*deltap/ &
363
51116
        (p(il,isublcl(il))+plcl(il))
364
51116
      cinb(il) = cinb(il) + min(0., dcin)
365
    END IF
366
  END DO
367
368
369
  ! c      ENDIF
370
371
  ! 2.2 Computation of CINA
372
  ! ---------------------
373
374
69110
  DO il = 1, ncum
375
68966
    lswitch2(il) = plcl(il) > p(il, itop(il)-1)
376

111395
    lswitch(il) = lswitch1(il) .AND. lswitch2(il)
377
  END DO
378
379
  ! 2.2.1 FIrst case : Plcl > P(itop-1)
380
  ! ---------------------------------
381
  ! In order to get Plfc, one may interpolate linearly buoyancies
382
  ! between P(itop) and P(itop-1).
383
69110
  DO il = 1, ncum
384
69110
    IF (lswitch(il)) THEN
385
      plfc(il) = (buoy(il,itop(il))*p(il,itop(il)-1)-buoy(il,itop( &
386
26681
        il)-1)*p(il,itop(il)))/(buoy(il,itop(il))-buoy(il,itop(il)-1))
387
    END IF
388
  END DO
389
390
  ! Upper part of CINA : integral from P(itop-1) to Plfc
391
69110
  DO il = 1, ncum
392
69110
    IF (lswitch(il)) THEN
393
26681
      deltap = p(il, itop(il)-1) - plfc(il)
394
26681
      dcin = rd*buoy(il, itop(il)-1)*deltap/(p(il,itop(il)-1)+plfc(il))
395
26681
      cina(il) = min(0., dcin)
396
    END IF
397
  END DO
398
399
  ! Middle part of CINA : integral from P(icb+1) to P(itop-1)
400
4032
  DO k = 1, nl
401
1866114
    DO il = 1, ncum
402

1865970
      IF (lswitch(il) .AND. k>=icb(il)+1 .AND. k<=itop(il)-2) THEN
403
5109
        deltap = p(il, k) - p(il, k+1)
404
5109
        dcin = 0.5*rd*(buoy(il,k)+buoy(il,k+1))*deltap/ph(il, k+1)
405
5109
        cina(il) = cina(il) + min(0., dcin)
406
      END IF
407
    END DO
408
  END DO
409
410
  ! Lower part of CINA : integral from Plcl to P(icb+1)
411
69110
  DO il = 1, ncum
412
69110
    IF (lswitch(il)) THEN
413
26681
      IF (plcl(il)>p(il,icb(il))) THEN
414
16509
        IF (icb(il)<itop(il)-1) THEN
415
3314
          deltap = p(il, icb(il)) - p(il, icb(il)+1)
416
          dcin = 0.5*rd*(buoy(il,icb(il))+buoy(il,icb(il)+1))*deltap/ &
417
3314
            ph(il, icb(il)+1)
418
3314
          cina(il) = cina(il) + min(0., dcin)
419
        END IF
420
421
16509
        deltap = plcl(il) - p(il, icb(il))
422
        dcin = rd*(buoylcl(il)+buoy(il,icb(il)))*deltap/ &
423
16509
          (plcl(il)+p(il,icb(il)))
424
16509
        cina(il) = cina(il) + min(0., dcin)
425
      ELSE
426
10172
        deltap = plcl(il) - p(il, icb(il)+1)
427
        dcin = rd*(buoylcl(il)+buoy(il,icb(il)+1))*deltap/ &
428
10172
          (plcl(il)+p(il,icb(il)+1))
429
10172
        cina(il) = cina(il) + min(0., dcin)
430
      END IF
431
    END IF
432
  END DO
433
434
69110
  DO il = 1, ncum
435

113641
    lswitch(il) = lswitch1(il) .AND. .NOT. lswitch2(il)
436
  END DO
437
  ! c      ELSE
438
439
  ! 2.2.2 Second case : Plcl lies between P(itop-1) and P(itop);
440
  ! ----------------------------------------------------------
441
  ! In order to get Plfc, one has to interpolate between P(itop) and Plcl.
442
69110
  DO il = 1, ncum
443
69110
    IF (lswitch(il)) THEN
444
      plfc(il) = (buoy(il,itop(il))*plcl(il)-buoylcl(il)*p(il,itop(il)))/ &
445
24435
        (buoy(il,itop(il))-buoylcl(il))
446
    END IF
447
  END DO
448
449
69110
  DO il = 1, ncum
450
69110
    IF (lswitch(il)) THEN
451
24435
      deltap = plcl(il) - plfc(il)
452
24435
      dcin = rd*buoylcl(il)*deltap/(plcl(il)+plfc(il))
453
24435
      cina(il) = min(0., dcin)
454
    END IF
455
  END DO
456
  ! c      ENDIF
457
458
459
460
144
  RETURN
461
END SUBROUTINE cv3_cine