This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
module_cu_bmj.F
2072 lines (2063 loc) · 66.2 KB
/
module_cu_bmj.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!-----------------------------------------------------------------------
!
!WRF:MODEL_LAYER:PHYSICS
!
!-----------------------------------------------------------------------
!
MODULE MODULE_CU_BMJ
!
!-----------------------------------------------------------------------
USE MODULE_MODEL_CONSTANTS
!-----------------------------------------------------------------------
!
REAL,PARAMETER :: &
& DSPC=-3000. &
& ,DTTOP=0.,EFIFC=5.0,EFIMN=0.20,EFMNT=0.70 &
& ,ELIWV=2.683E6,ENPLO=20000.,ENPUP=15000. &
& ,EPSDN=1.05,EPSDT=0. &
& ,EPSNTP=.0001,EPSNTT=.0001,EPSPR=1.E-7 &
& ,EPSUP=1.00 &
& ,FR=1.00,FSL=0.85,FSS=0.85 &
& ,FUP=0. &
& ,PBM=13000.,PFRZ=15000.,PNO=1000. &
& ,PONE=2500.,PQM=20000. &
& ,PSH=20000.,PSHU=45000. &
& ,RENDP=1./(ENPLO-ENPUP) &
& ,RHLSC=0.00,RHHSC=1.10 &
& ,ROW=1.E3 &
& ,STABDF=0.90,STABDS=0.90 &
& ,STABS=1.0,STRESH=1.10 &
& ,DTSHAL=-1.0,TREL=2400.
!
REAL,PARAMETER :: DTtrigr=-0.0 &
,DTPtrigr=DTtrigr*PONE !<-- Average parcel virtual temperature deficit over depth PONE.
!<-- NOTE: CAPEtrigr is scaled by the cloud base temperature (see below)
!
REAL,PARAMETER :: DSPBFL=-3875.*FR &
& ,DSP0FL=-5875.*FR &
& ,DSPTFL=-1875.*FR &
& ,DSPBFS=-3875. &
& ,DSP0FS=-5875. &
& ,DSPTFS=-1875.
!
REAL,PARAMETER :: PL=2500.,PLQ=70000.,PH=105000. &
& ,THL=210.,THH=365.,THHQ=325.
!
INTEGER,PARAMETER :: ITB=76,JTB=134,ITBQ=152,JTBQ=440
!
INTEGER,PARAMETER :: ITREFI_MAX=3
!
!*** ARRAYS FOR LOOKUP TABLES
!
REAL,DIMENSION(ITB),PRIVATE,SAVE :: STHE,THE0
REAL,DIMENSION(JTB),PRIVATE,SAVE :: QS0,SQS
REAL,DIMENSION(ITBQ),PRIVATE,SAVE :: STHEQ,THE0Q
REAL,DIMENSION(ITB,JTB),PRIVATE,SAVE :: PTBL
REAL,DIMENSION(JTB,ITB),PRIVATE,SAVE :: TTBL
REAL,DIMENSION(JTBQ,ITBQ),PRIVATE,SAVE :: TTBLQ
!*** SHARE COPIES FOR MODULE_BL_MYJPBL
!
REAL,DIMENSION(JTB) :: QS0_EXP,SQS_EXP
REAL,DIMENSION(ITB,JTB) :: PTBL_EXP
!
REAL,PARAMETER :: RDP=(ITB-1.)/(PH-PL),RDPQ=(ITBQ-1.)/(PH-PLQ) &
& ,RDQ=ITB-1,RDTH=(JTB-1.)/(THH-THL) &
& ,RDTHE=JTB-1.,RDTHEQ=JTBQ-1. &
& ,RSFCP=1./101300.
!
REAL,PARAMETER :: AVGEFI=(EFIMN+1.)*0.5
!
!-----------------------------------------------------------------------
!
CONTAINS
!
!-----------------------------------------------------------------------
SUBROUTINE BMJDRV( &
& IDS,IDE,JDS,JDE,KDS,KDE &
& ,IMS,IME,JMS,JME,KMS,KME &
& ,ITS,ITE,JTS,JTE,KTS,KTE &
& ,DT,ITIMESTEP,STEPCU &
& ,RAINCV,PRATEC,CUTOP,CUBOT,KPBL &
& ,TH,T,QV &
& ,PINT,PMID,PI,RHO,DZ8W &
& ,CP,R,ELWV,ELIV,G,TFRZ,D608 &
& ,CLDEFI,LOWLYR,XLAND,CU_ACT_FLAG &
! optional
& ,RTHCUTEN, RQVCUTEN &
& )
!-----------------------------------------------------------------------
IMPLICIT NONE
!-----------------------------------------------------------------------
INTEGER,INTENT(IN) :: IDS,IDE,JDS,JDE,KDS,KDE &
& ,IMS,IME,JMS,JME,KMS,KME &
& ,ITS,ITE,JTS,JTE,KTS,KTE
!
INTEGER,INTENT(IN) :: ITIMESTEP,STEPCU
!
INTEGER,DIMENSION(IMS:IME,JMS:JME),INTENT(IN) :: KPBL,LOWLYR
!
REAL,INTENT(IN) :: CP,DT,ELIV,ELWV,G,R,TFRZ,D608
!
REAL,DIMENSION(IMS:IME,JMS:JME),INTENT(IN) :: XLAND
!
REAL,DIMENSION(IMS:IME,KMS:KME,JMS:JME),INTENT(IN) :: DZ8W &
& ,PI,PINT &
& ,PMID,QV &
& ,RHO,T,TH
!
REAL,DIMENSION(IMS:IME,KMS:KME,JMS:JME) &
& ,OPTIONAL &
& ,INTENT(INOUT) :: RQVCUTEN,RTHCUTEN
!
REAL,DIMENSION(IMS:IME,JMS:JME),INTENT(INOUT) :: CLDEFI,RAINCV, &
PRATEC
!
REAL,DIMENSION(IMS:IME,JMS:JME),INTENT(OUT) :: CUBOT,CUTOP
!
LOGICAL,DIMENSION(IMS:IME,JMS:JME),INTENT(INOUT) :: CU_ACT_FLAG
!
!-----------------------------------------------------------------------
!***
!*** LOCAL VARIABLES
!***
!-----------------------------------------------------------------------
INTEGER :: LBOT,LPBL,LTOP
!
REAL :: DTCNVC,LANDMASK,PCPCOL,PSFC,PTOP
!
REAL,DIMENSION(KTS:KTE) :: DPCOL,DQDT,DTDT,PCOL,QCOL,TCOL
!
INTEGER :: I,J,K,KFLIP,LMH
!*** Begin debugging convection
REAL :: DELQ,DELT,PLYR
INTEGER :: IMD,JMD
LOGICAL :: PRINT_DIAG
!*** End debugging convection
!
!-----------------------------------------------------------------------
!***********************************************************************
!-----------------------------------------------------------------------
!
!*** PREPARE TO CALL BMJ CONVECTION SCHEME
!
!-----------------------------------------------------------------------
!*** Begin debugging convection
IMD=(IMS+IME)/2
JMD=(JMS+JME)/2
PRINT_DIAG=.FALSE.
!*** End debugging convection
!
DO J=JTS,JTE
DO I=ITS,ITE
CU_ACT_FLAG(I,J)=.TRUE.
ENDDO
ENDDO
!
DTCNVC=DT*STEPCU
!
DO J=JTS,JTE
DO I=ITS,ITE
!
DO K=KTS,KTE
DQDT(K)=0.
DTDT(K)=0.
ENDDO
!
RAINCV(I,J)=0.
PRATEC(I,J)=0.
PCPCOL=0.
PSFC=PINT(I,LOWLYR(I,J),J)
PTOP=PINT(I,KTE+1,J) ! KTE+1=KME
!
!*** CONVERT TO BMJ LAND MASK (1.0 FOR SEA; 0.0 FOR LAND)
!
LANDMASK=XLAND(I,J)-1.
!
!*** FILL 1-D VERTICAL ARRAYS
!*** AND FLIP DIRECTION SINCE BMJ SCHEME
!*** COUNTS DOWNWARD FROM THE DOMAIN'S TOP
!
DO K=KTS,KTE
KFLIP=KTE+1-K
!
!*** CONVERT FROM MIXING RATIO TO SPECIFIC HUMIDITY
!
QCOL(K)=MAX(EPSQ,QV(I,KFLIP,J)/(1.+QV(I,KFLIP,J)))
TCOL(K)=T(I,KFLIP,J)
PCOL(K)=PMID(I,KFLIP,J)
! DPCOL(K)=PINT(I,KFLIP,J)-PINT(I,KFLIP+1,J)
DPCOL(K)=RHO(I,KFLIP,J)*G*DZ8W(I,KFLIP,J)
ENDDO
!
!*** LOWEST LAYER ABOVE GROUND MUST ALSO BE FLIPPED
!
LMH=KTE+1-LOWLYR(I,J)
LPBL=KTE+1-KPBL(I,J)
!-----------------------------------------------------------------------
!***
!*** CALL CONVECTION
!***
!-----------------------------------------------------------------------
!*** Begin debugging convection
! PRINT_DIAG=.FALSE.
! IF(I==IMD.AND.J==JMD)PRINT_DIAG=.TRUE.
!*** End debugging convection
!-----------------------------------------------------------------------
CALL BMJ(ITIMESTEP,I,J,DTCNVC,LMH,LANDMASK,CLDEFI(I,J) &
& ,DPCOL,PCOL,QCOL,TCOL,PSFC,PTOP &
& ,DQDT,DTDT,PCPCOL,LBOT,LTOP,LPBL &
& ,CP,R,ELWV,ELIV,G,TFRZ,D608 &
& ,PRINT_DIAG &
& ,IDS,IDE,JDS,JDE,KDS,KDE &
& ,IMS,IME,JMS,JME,KMS,KME &
& ,ITS,ITE,JTS,JTE,KTS,KTE)
!-----------------------------------------------------------------------
!
!*** COMPUTE HEATING AND MOISTENING TENDENCIES
!
IF ( PRESENT( RTHCUTEN ) .AND. PRESENT( RQVCUTEN )) THEN
DO K=KTS,KTE
KFLIP=KTE+1-K
RTHCUTEN(I,K,J)=DTDT(KFLIP)/PI(I,K,J)
!
!*** CONVERT FROM SPECIFIC HUMIDTY BACK TO MIXING RATIO
!
RQVCUTEN(I,K,J)=DQDT(KFLIP)/(1.-QCOL(KFLIP))**2
ENDDO
ENDIF
!
!*** ALL UNITS IN BMJ SCHEME ARE MKS, THUS CONVERT PRECIP FROM METERS
!*** TO MILLIMETERS PER STEP FOR OUTPUT.
!
RAINCV(I,J)=PCPCOL*1.E3/STEPCU
PRATEC(I,J)=PCPCOL*1.E3/(STEPCU * DT)
!
!*** CONVECTIVE CLOUD TOP AND BOTTOM FROM THIS CALL
!
CUTOP(I,J)=REAL(KTE+1-LTOP)
CUBOT(I,J)=REAL(KTE+1-LBOT)
!
!-----------------------------------------------------------------------
!*** Begin debugging convection
IF(PRINT_DIAG)THEN
DELT=0.
DELQ=0.
PLYR=0.
IF(LBOT>0.AND.LTOP<LBOT)THEN
DO K=LTOP,LBOT
PLYR=PLYR+DPCOL(K)
DELQ=DELQ+DPCOL(K)*DTCNVC*ABS(DQDT(K))
DELT=DELT+DPCOL(K)*DTCNVC*ABS(DTDT(K))
ENDDO
DELQ=DELQ/PLYR
DELT=DELT/PLYR
ENDIF
!
WRITE(6,"(2a,2i4,3e12.4,f7.2,4i3)") &
'{cu3 i,j,PCPCOL,DTavg,DQavg,PLYR,' &
,'LBOT,LTOP,CUBOT,CUTOP = ' &
,i,j, PCPCOL,DELT,1000.*DELQ,.01*PLYR &
,LBOT,LTOP,NINT(CUBOT(I,J)),NINT(CUTOP(I,J))
!
IF(PLYR> 0.)THEN
DO K=LBOT,LTOP,-1
KFLIP=KTE+1-K
WRITE(6,"(a,i3,2e12.4,f7.2)") '{cu3a KFLIP,DT,DQ,DP = ' &
,KFLIP,DTCNVC*DTDT(K),1000.*DTCNVC*DQDT(K),.01*DPCOL(K)
ENDDO
ENDIF
ENDIF
!*** End debugging convection
!-----------------------------------------------------------------------
!
ENDDO
ENDDO
!
END SUBROUTINE BMJDRV
!-----------------------------------------------------------------------
!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
!-----------------------------------------------------------------------
SUBROUTINE BMJ &
!-----------------------------------------------------------------------
& (ITIMESTEP,I,J,DTCNVC,LMH,SM,CLDEFI &
& ,DPRS,PRSMID,Q,T,PSFC,PT &
& ,DQDT,DTDT,PCPCOL,LBOT,LTOP,LPBL &
& ,CP,R,ELWV,ELIV,G,TFRZ,D608 &
& ,PRINT_DIAG &
& ,IDS,IDE,JDS,JDE,KDS,KDE &
& ,IMS,IME,JMS,JME,KMS,KME &
& ,ITS,ITE,JTS,JTE,KTS,KTE)
!-----------------------------------------------------------------------
IMPLICIT NONE
!-----------------------------------------------------------------------
INTEGER,INTENT(IN) :: IDS,IDE,JDS,JDE,KDS,KDE &
,IMS,IME,JMS,JME,KMS,KME &
,ITS,ITE,JTS,JTE,KTS,KTE &
,I,J,ITIMESTEP
!
INTEGER,INTENT(IN) :: LMH,LPBL
!
INTEGER,INTENT(OUT) :: LBOT,LTOP
!
REAL,INTENT(IN) :: CP,D608,DTCNVC,ELIV,ELWV,G,PSFC,PT,R,SM,TFRZ
!
REAL,DIMENSION(KTS:KTE),INTENT(IN) :: DPRS,PRSMID,Q,T
!
REAL,INTENT(INOUT) :: CLDEFI,PCPCOL
!
REAL,DIMENSION(KTS:KTE),INTENT(INOUT) :: DQDT,DTDT
!
!-----------------------------------------------------------------------
!*** DEFINE LOCAL VARIABLES
!-----------------------------------------------------------------------
!
REAL,DIMENSION(KTS:KTE) :: APEK,APESK,EL,FPK &
,PK,PSK,QK,QREFK,QSATK &
,THERK,THEVRF,THSK &
,THVMOD,THVREF,TK,TREFK
REAL,DIMENSION(KTS:KTE) :: APE,DIFQ,DIFT,THEE,THES,TREF
!
REAL,DIMENSION(KTS:KTE) :: CPE,CPEcnv,DTV,DTVcnv,THEScnv !<-- CPE for shallow convection buoyancy check (24 Aug 2006)
!
LOGICAL :: DEEP,SHALLOW
!
!*** Begin debugging convection
LOGICAL :: PRINT_DIAG
!*** End debugging convection
!
!-----------------------------------------------------------------------
!***
!*** LOCAL SCALARS
!***
!-----------------------------------------------------------------------
REAL :: APEKL,APEKXX,APEKXY,APES,APESTS &
& ,AVRGT,AVRGTL,BQ,BQK,BQS00K,BQS10K &
& ,CAPA,CUP,DEN,DENTPY,DEPMIN,DEPTH &
& ,DEPWL,DHDT,DIFQL,DIFTL,DP,DPKL,DPLO,DPMIX,DPOT &
& ,DPUP,DQREF,DRHDP,DRHEAT,DSP &
& ,DSP0,DSP0K,DSPB,DSPBK,DSPT,DSPTK &
& ,DSQ,DST,DSTQ,DTHEM,DTDP,EFI &
& ,FEFI,FFUP,FPRS,FPTK,HCORR &
& ,OTSUM,P,P00K,P01K,P10K,P11K &
& ,PART1,PART2,PART3,PBOT,PBOTFC,PBTK &
& ,PK0,PKB,PKL,PKT,PKXXXX,PKXXXY &
& ,PLMH,PELEVFC,PBTmx,plo,POTSUM,PP1,PPK,PRECK &
& ,PRESK,PSP,PSUM,PTHRS,PTOP,PTPK,PUP &
& ,QBT,QKL,QNEW,QOTSUM,QQ1,QQK,QRFKL &
& ,QRFTP,QSP,QSUM,QUP,RDP0T &
& ,RDPSUM,RDTCNVC,RHH,RHL,RHMAX,ROTSUM,RTBAR,RHAVG &
& ,SM1,SMIX,SQ,SQK,SQS00K,SQS10K,STABDL,SUMDE,SUMDP &
& ,SUMDT,TAUK,TAUKSC,TCORR,THBT,THERKX,THERKY &
& ,THESP,THSKL,THTPK,THVMKL,TKL,TNEW &
& ,TQ,TQK,TREFKX,TRFKL,trmlo,trmup,TSKL,tsp,TTH &
& ,TTHK,TUP &
& ,CAPEcnv,PSPcnv,THBTcnv,CAPEtrigr,CAPE &
& ,TLEV2,QSAT1,QSAT2,RHSHmax
!
INTEGER :: IQ,IQTB,IT,ITER,ITREFI,ITTB,ITTBK,KB,KNUMH,KNUML &
& ,L,L0,L0M1,LB,LBM1,LCOR,LPT1 &
& ,LQM,LSHU,LTP1,LTP2,LTSH, LBOTcnv,LTOPcnv,LMID
!-----------------------------------------------------------------------
!
REAL,PARAMETER :: DSPBSL=DSPBFL*FSL,DSP0SL=DSP0FL*FSL &
& ,DSPTSL=DSPTFL*FSL &
& ,DSPBSS=DSPBFS*FSS,DSP0SS=DSP0FS*FSS &
& ,DSPTSS=DSPTFS*FSS
!
REAL,PARAMETER :: ELEVFC=0.6,STEFI=1.
!
REAL,PARAMETER :: SLOPBL=(DSPBFL-DSPBSL)/(1.-EFIMN) &
& ,SLOP0L=(DSP0FL-DSP0SL)/(1.-EFIMN) &
& ,SLOPTL=(DSPTFL-DSPTSL)/(1.-EFIMN) &
& ,SLOPBS=(DSPBFS-DSPBSS)/(1.-EFIMN) &
& ,SLOP0S=(DSP0FS-DSP0SS)/(1.-EFIMN) &
& ,SLOPTS=(DSPTFS-DSPTSS)/(1.-EFIMN) &
& ,SLOPST=(STABDF-STABDS)/(1.-EFIMN) &
& ,SLOPE=(1.-EFMNT)/(1.-EFIMN)
!
REAL :: A23M4L,CPRLG,ELOCP,RCP,QWAT
!-----------------------------------------------------------------------
!***********************************************************************
!-----------------------------------------------------------------------
CAPA=R/CP
CPRLG=CP/(ROW*G*ELWV)
ELOCP=ELIWV/CP
RCP=1./CP
A23M4L=A2*(A3-A4)*ELWV
RDTCNVC=1./DTCNVC
DEPMIN=PSH*PSFC*RSFCP
!
DEEP=.FALSE.
SHALLOW=.FALSE.
!
DSP0=0.
DSPB=0.
DSPT=0.
!-----------------------------------------------------------------------
TAUK=DTCNVC/TREL
TAUKSC=DTCNVC/(1.0*TREL)
!-----------------------------------------------------------------------
!-----------------------------PREPARATIONS------------------------------
!-----------------------------------------------------------------------
LBOT=LMH
PCPCOL=0.
TREF(KTS)=T(KTS)
!
DO L=KTS,LMH
APESTS=PRSMID(L)
APE(L)=(1.E5/APESTS)**CAPA
CPEcnv(L)=0.
DTVcnv(L)=0.
THEScnv(L)=0.
ENDDO
!
!-----------------------------------------------------------------------
!----------------SEARCH FOR MAXIMUM BUOYANCY LEVEL----------------------
!-----------------------------------------------------------------------
!
PLMH=PRSMID(LMH)
PELEVFC=PLMH*ELEVFC
PBTmx=PRSMID(LMH)-PONE
CAPEcnv=0.
PSPcnv=0.
THBTcnv=0.
LBOTcnv=LBOT
LTOPcnv=LBOT
!
!-----------------------------------------------------------------------
!----------------TRIAL MAXIMUM BUOYANCY LEVEL VARIABLES-----------------
!-----------------------------------------------------------------------
!
max_buoy_loop: DO KB=LMH,1,-1
!
!-----------------------------------------------------------------------
!
PKL=PRSMID(KB)
! IF (PKL<PELEVFC .OR. T(KB)<=TFRZ) EXIT
IF (PKL<PELEVFC) EXIT
LBOT=LMH
LTOP=LMH
!
!-----------------------------------------------------------------------
!*** SEARCH OVER A SCALED DEPTH IN FINDING THE PARCEL
!*** WITH THE MAX THETA-E
!-----------------------------------------------------------------------
!
QBT=Q(KB)
THBT=T(KB)*APE(KB)
TTH=(THBT-THL)*RDTH
QQ1=TTH-AINT(TTH)
ITTB=INT(TTH)+1
!----------------KEEPING INDICES WITHIN THE TABLE-----------------------
IF(ITTB<1)THEN
ITTB=1
QQ1=0.
ELSE IF(ITTB>=JTB)THEN
ITTB=JTB-1
QQ1=0.
ENDIF
!--------------BASE AND SCALING FACTOR FOR SPEC. HUMIDITY---------------
ITTBK=ITTB
BQS00K=QS0(ITTBK)
SQS00K=SQS(ITTBK)
BQS10K=QS0(ITTBK+1)
SQS10K=SQS(ITTBK+1)
!--------------SCALING SPEC. HUMIDITY & TABLE INDEX---------------------
BQ=(BQS10K-BQS00K)*QQ1+BQS00K
SQ=(SQS10K-SQS00K)*QQ1+SQS00K
TQ=(QBT-BQ)/SQ*RDQ
PP1=TQ-AINT(TQ)
IQTB=INT(TQ)+1
!----------------KEEPING INDICES WITHIN THE TABLE-----------------------
IF(IQTB<1)THEN
IQTB=1
PP1=0.
ELSE IF(IQTB>=ITB)THEN
IQTB=ITB-1
PP1=0.
ENDIF
!--------------SATURATION PRESSURE AT FOUR SURROUNDING TABLE PTS.-------
IQ=IQTB
IT=ITTB
P00K=PTBL(IQ ,IT )
P10K=PTBL(IQ+1,IT )
P01K=PTBL(IQ ,IT+1)
P11K=PTBL(IQ+1,IT+1)
!
!--------------SATURATION POINT VARIABLES AT THE BOTTOM-----------------
!
PSP=P00K+(P10K-P00K)*PP1+(P01K-P00K)*QQ1 &
& +(P00K-P10K-P01K+P11K)*PP1*QQ1
APES=(1.E5/PSP)**CAPA
THESP=THBT*EXP(ELOCP*QBT*APES/THBT)
!
!-----------------------------------------------------------------------
!-----------CHOOSE CLOUD BASE AS MODEL LEVEL JUST BELOW PSP-------------
!-----------------------------------------------------------------------
!
DO L=KTS,LMH-1
P=PRSMID(L)
IF(P<PSP.AND.P>=PQM)LBOT=L+1
ENDDO
!***
!*** WARNING: LBOT MUST NOT BE > LMH-1 IN SHALLOW CONVECTION
!*** MAKE SURE CLOUD BASE IS AT LEAST PONE ABOVE THE SURFACE
!***
PBOT=PRSMID(LBOT)
IF(PBOT>=PBTmx.OR.LBOT>=LMH)THEN
DO L=KTS,LMH-1
P=PRSMID(L)
IF(P<PBTmx)LBOT=L
ENDDO
PBOT=PRSMID(LBOT)
ENDIF
!
!-----------------------------------------------------------------------
!----------------CLOUD TOP COMPUTATION----------------------------------
!-----------------------------------------------------------------------
!
LTOP=LBOT
PTOP=PBOT
DO L=LMH,KTS,-1
THES(L)=THESP
ENDDO
!
!-----------------------------------------------------------------------
!### BEGIN: ########### WARNING ########### WARNING ###########
!-----------------------------------------------------------------------
!
!### IMPORTANT: THIS "DO KB=LMH,1,-1" loop must be broken up into two
! separate loops in order for entrainment as programmed below to work
! properly.
!
!--------------- ENTRAINMENT DURING PARCEL ASCENT --------------------
!
! DO L=LMH,KB,-1
! THES(L)=THESP
! ENDDO
!
! DO L=KTS,LMH
! THEE(L)=THES(L)
! ENDDO
!!
! FEFI=(CLDEFI-EFIMN)*SLOPE+EFMNT
! FFUP=FUP/(FEFI*FEFI)
!!
! IF(PBOT>ENPLO)THEN
! FPRS=1.
! ELSEIF(PBOT>ENPUP)THEN
! FPRS=(PBOT-ENPUP)*RENDP
! ELSE
! FPRS=0.
! ENDIF
!!
! FFUP=FFUP*FPRS*FPRS*0.5
! DPUP=DPRS(KB)
!!
! DO L=KB-1,KTS,-1
! DPLO=DPUP
! DPUP=DPRS(L)
!!
! THES(L)=((-FFUP*DPLO+1.)*THES(L+1) &
! & +(THEE(L)*DPUP+THEE(L+1)*DPLO)*FFUP) &
! & /(FFUP*DPUP+1.)
! ENDDO
!
!-----------------------------------------------------------------------
!### END: ########### WARNING ########### WARNING ###########
!-----------------------------------------------------------------------
!!
!-----------------------------------------------------------------------
!!*** COMPUTE PARCEL TEMPERATURE ALONG THE ASCENT TRAJECTORY
!!*** SCALING PRESSURE & TT TABLE INDEX.
!-----------------------------------------------------------------------
!!
!!
! DO L=LMH,KTS,-1
!!
! PRESK=PRSMID(L)
!!
! IF(PRESK<PLQ)THEN
! CALL TTBLEX(ITB,JTB,PL,PRESK,RDP,RDTHE &
! & ,STHE,THE0,THES(L),TTBL,TREF(L))
! ELSE
! CALL TTBLEX(ITBQ,JTBQ,PLQ,PRESK,RDPQ,RDTHEQ &
! & ,STHEQ,THE0Q,THES(L),TTBLQ,TREF(L))
! ENDIF
!!
! ENDDO
!!
!!-----------------------------------------------------------------------
!!----------------BUOYANCY CHECK-----------------------------------------
!!-----------------------------------------------------------------------
!!
! DO L=LMH,KTS,-1
! IF(TREF(L)>T(L)-DTTOP)LTOP=L
! ENDDO
!!
!!*** CLOUD TOP PRESSURE
!!
! PTOP=PRSMID(LTOP)
!
!------------------FIRST ENTROPY CHECK----------------------------------
!
DO L=KTS,LMH
CPE(L)=0.
DTV(L)=0.
ENDDO
!-----------------------------------------------------------------------
! lbot_ltop: IF(LBOT>LTOP)THEN
!-----------------------------------------------------------------------
!-- Begin: Buoyancy check including deep convection (24 Aug 2006)
!-----------------------------------------------------------------------
DENTPY=0.
L=KB
PLO=PRSMID(L)
TRMLO=0.
CAPEtrigr=DTPtrigr/T(LBOT)
!
!--- Below cloud base
!
IF(KB>LBOT) THEN
DO L=KB-1,LBOT+1,-1
PUP=PRSMID(L)
TUP=THBT/APE(L)
DP=PLO-PUP
TRMUP=(TUP*(QBT*0.608+1.) &
& -T(L)*(Q(L)*0.608+1.))*0.5 &
& /(T(L)*(Q(L)*0.608+1.))
DTV(L)=TRMLO+TRMUP
DENTPY=DTV(L)*DP+DENTPY
CPE(L)=DENTPY
IF (DENTPY < CAPEtrigr) GO TO 170
PLO=PUP
TRMLO=TRMUP
ENDDO
ELSE
L=LBOT+1
PLO=PRSMID(L)
TUP=THBT/APE(L)
TRMLO=(TUP*(QBT*0.608+1.) &
& -T(L)*(Q(L)*0.608+1.))*0.5 &
& /(T(L)*(Q(L)*0.608+1.))
ENDIF ! IF(KB>LBOT) THEN
!
!--- At cloud base
!
L=LBOT
PUP=PSP
TUP=THBT/APES
TSP=(T(L+1)-T(L))/(PLO-PBOT) &
& *(PUP-PBOT)+T(L)
QSP=(Q(L+1)-Q(L))/(PLO-PBOT) &
& *(PUP-PBOT)+Q(L)
DP=PLO-PUP
TRMUP=(TUP*(QBT*0.608+1.) &
& -TSP*(QSP*0.608+1.))*0.5 &
& /(TSP*(QSP*0.608+1.))
DTV(L)=TRMLO+TRMUP
DENTPY=DTV(L)*DP+DENTPY
CPE(L)=DENTPY
DTV(L)=DTV(L)*DP
PLO=PUP
TRMLO=TRMUP
PUP=PRSMID(L)
!
!--- Calculate updraft temperature along moist adiabat (TUP)
!
IF(PUP<PLQ)THEN
CALL TTBLEX(ITB,JTB,PL,PUP,RDP,RDTHE &
& ,STHE,THE0,THES(L),TTBL,TUP)
ELSE
CALL TTBLEX(ITBQ,JTBQ,PLQ,PUP,RDPQ,RDTHEQ &
& ,STHEQ,THE0Q,THES(L),TTBLQ,TUP)
ENDIF
!
QUP=PQ0/PUP*EXP(A2*(TUP-A3)/(TUP-A4))
QWAT=QBT-QUP !-- Water loading effects, reversible adiabat
DP=PLO-PUP
TRMUP=(TUP*(QUP*0.608+1.-QWAT) &
& -T(L)*(Q(L)*0.608+1.))*0.5 &
& /(T(L)*(Q(L)*0.608+1.))
DENTPY=(TRMLO+TRMUP)*DP+DENTPY
CPE(L)=DENTPY
DTV(L)=(DTV(L)+(TRMLO+TRMUP)*DP)/(PRSMID(LBOT+1)-PRSMID(LBOT))
!
IF (DENTPY < CAPEtrigr) GO TO 170
!
PLO=PUP
TRMLO=TRMUP
!
!-----------------------------------------------------------------------
!--- In cloud above cloud base
!-----------------------------------------------------------------------
!
DO L=LBOT-1,KTS,-1
PUP=PRSMID(L)
!
!--- Calculate updraft temperature along moist adiabat (TUP)
!
IF(PUP<PLQ)THEN
CALL TTBLEX(ITB,JTB,PL,PUP,RDP,RDTHE &
& ,STHE,THE0,THES(L),TTBL,TUP)
ELSE
CALL TTBLEX(ITBQ,JTBQ,PLQ,PUP,RDPQ,RDTHEQ &
& ,STHEQ,THE0Q,THES(L),TTBLQ,TUP)
ENDIF
!
QUP=PQ0/PUP*EXP(A2*(TUP-A3)/(TUP-A4))
QWAT=QBT-QUP !-- Water loading effects, reversible adiabat
DP=PLO-PUP
TRMUP=(TUP*(QUP*0.608+1.-QWAT) &
& -T(L)*(Q(L)*0.608+1.))*0.5 &
& /(T(L)*(Q(L)*0.608+1.))
DTV(L)=TRMLO+TRMUP
DENTPY=DTV(L)*DP+DENTPY
CPE(L)=DENTPY
!
IF (DENTPY < CAPEtrigr) GO TO 170
!
PLO=PUP
TRMLO=TRMUP
ENDDO
!
!-----------------------------------------------------------------------
!
170 LTP1=KB
CAPE=0.
!
!-----------------------------------------------------------------------
!--- Cloud top level (LTOP) is located where CAPE is a maximum
!--- Exit cloud-top search if CAPE < CAPEtrigr
!-----------------------------------------------------------------------
!
DO L=KB,KTS,-1
IF (CPE(L) < CAPEtrigr) THEN
EXIT
ELSE IF (CPE(L) > CAPE) THEN
LTP1=L
CAPE=CPE(L)
ENDIF
ENDDO !-- End DO L=KB,KTS,-1
!
LTOP=MIN(LTP1,LBOT)
!
!-----------------------------------------------------------------------
!--------------- CHECK FOR MAXIMUM INSTABILITY ------------------------
!-----------------------------------------------------------------------
IF(CAPE > CAPEcnv) THEN
CAPEcnv=CAPE
PSPcnv=PSP
THBTcnv=THBT
LBOTcnv=LBOT
LTOPcnv=LTOP
DO L=LMH,KTS,-1
CPEcnv(L)=CPE(L)
DTVcnv(L)=DTV(L)
THEScnv(L)=THES(L)
ENDDO
ENDIF ! End IF(CAPE > CAPEcnv) THEN
!
! ENDIF lbot_ltop
!
!-----------------------------------------------------------------------
!
ENDDO max_buoy_loop
!
!-----------------------------------------------------------------------
!------------------------ MAXIMUM INSTABILITY ------------------------
!-----------------------------------------------------------------------
!
IF(CAPEcnv > 0.) THEN
PSP=PSPcnv
THBT=THBTcnv
LBOT=LBOTcnv
LTOP=LTOPcnv
PBOT=PRSMID(LBOT)
PTOP=PRSMID(LTOP)
!
DO L=LMH,KTS,-1
CPE(L)=CPEcnv(L)
DTV(L)=DTVcnv(L)
THES(L)=THEScnv(L)
ENDDO
!
ENDIF
!
!-----------------------------------------------------------------------
!----- Quick exit if cloud is too thin or no CAPE is present ---------
!-----------------------------------------------------------------------
!
IF(PTOP>PBOT-PNO.OR.LTOP>LBOT-2.OR.CAPEcnv<=0.)THEN
LBOT=0
LTOP=KTE
PBOT=PRSMID(LMH)
PTOP=PBOT
CLDEFI=AVGEFI*SM+STEFI*(1.-SM)
GO TO 800
ENDIF
!
!*** DEPTH OF CLOUD REQUIRED TO MAKE THE POINT A DEEP CONVECTION POINT
!*** IS A SCALED VALUE OF PSFC.
!
DEPTH=PBOT-PTOP
!
IF(DEPTH>=DEPMIN) THEN
DEEP=.TRUE.
ELSE
SHALLOW=.TRUE.
GO TO 600
ENDIF
!
!-----------------------------------------------------------------------
!DCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD
!DCDCDCDCDCDCDCDCDCDCDC DEEP CONVECTION DCDCDCDCDCDCDCDCDCDCDCDCDCD
!DCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD
!-----------------------------------------------------------------------
!
300 CONTINUE
!
LB =LBOT
EFI=CLDEFI
!-----------------------------------------------------------------------
!--------------INITIALIZE VARIABLES IN THE CONVECTIVE COLUMN------------
!-----------------------------------------------------------------------
!***
!*** ONE SHOULD NOTE THAT THE VALUES ASSIGNED TO THE ARRAY TREFK
!*** IN THE FOLLOWING LOOP ARE REALLY ONLY RELEVANT IN ANCHORING THE
!*** REFERENCE TEMPERATURE PROFILE AT LEVEL LB. WHEN BUILDING THE
!*** REFERENCE PROFILE FROM CLOUD BASE, THEN ASSIGNING THE
!*** AMBIENT TEMPERATURE TO TREFK IS ACCEPTABLE. HOWEVER, WHEN
!*** BUILDING THE REFERENCE PROFILE FROM SOME OTHER LEVEL (SUCH AS
!*** ONE LEVEL ABOVE THE GROUND), THEN TREFK SHOULD BE FILLED WITH
!*** THE TEMPERATURES IN TREF(L) WHICH ARE THE TEMPERATURES OF
!*** THE MOIST ADIABAT THROUGH CLOUD BASE. BY THE TIME THE LINE
!*** NUMBERED 450 HAS BEEN REACHED, TREFK ACTUALLY DOES HOLD THE
!*** REFERENCE TEMPERATURE PROFILE.
!***
DO L=KTS,LMH
DIFT (L)=0.
DIFQ (L)=0.
TKL =T(L)
TK (L)=TKL
TREFK (L)=TKL
QKL =Q(L)
QK (L)=QKL
QREFK (L)=QKL
PKL =PRSMID(L)
PK (L)=PKL
PSK (L)=PKL
APEKL =APE(L)
APEK (L)=APEKL
!
!--- Calculate temperature along moist adiabat (TREF)
!
IF(PKL<PLQ)THEN
CALL TTBLEX(ITB,JTB,PL,PKL,RDP,RDTHE &
& ,STHE,THE0,THES(L),TTBL,TREF(L))
ELSE
CALL TTBLEX(ITBQ,JTBQ,PLQ,PKL,RDPQ,RDTHEQ &
& ,STHEQ,THE0Q,THES(L),TTBLQ,TREF(L))
ENDIF
THERK (L)=TREF(L)*APEKL
ENDDO
!
!------------DEEP CONVECTION REFERENCE TEMPERATURE PROFILE------------
!
LTP1=LTOP+1
LBM1=LB-1
PKB=PK(LB)
PKT=PK(LTOP)
STABDL=(EFI-EFIMN)*SLOPST+STABDS
!
!------------TEMPERATURE REFERENCE PROFILE BELOW FREEZING LEVEL-------
!
EL(LB) = ELWV
L0=LB
PK0=PK(LB)
TREFKX=TREFK(LB)
THERKX=THERK(LB)
APEKXX=APEK(LB)
THERKY=THERK(LBM1)
APEKXY=APEK(LBM1)
!
DO L=LBM1,LTOP,-1
IF(T(L+1)<TFRZ)GO TO 430
TREFKX=((THERKY-THERKX)*STABDL &
& +TREFKX*APEKXX)/APEKXY
TREFK(L)=TREFKX
EL(L)=ELWV
APEKXX=APEKXY
THERKX=THERKY
APEKXY=APEK(L-1)
THERKY=THERK(L-1)
L0=L
PK0=PK(L0)
ENDDO
!
!--------------FREEZING LEVEL AT OR ABOVE THE CLOUD TOP-----------------
!
GO TO 450
!
!--------------TEMPERATURE REFERENCE PROFILE ABOVE FREEZING LEVEL-------
!
430 L0M1=L0-1
RDP0T=1./(PK0-PKT)
DTHEM=THERK(L0)-TREFK(L0)*APEK(L0)
!
DO L=LTOP,L0M1
TREFK(L)=(THERK(L)-(PK(L)-PKT)*DTHEM*RDP0T)/APEK(L)
EL(L)=ELWV !ELIV
ENDDO
!
!-----------------------------------------------------------------------
!--------------DEEP CONVECTION REFERENCE HUMIDITY PROFILE---------------
!-----------------------------------------------------------------------
!
!*** DEPWL IS THE PRESSURE DIFFERENCE BETWEEN CLOUD BASE AND
!*** THE FREEZING LEVEL
!
450 CONTINUE
DEPWL=PKB-PK0
DEPTH=PFRZ*PSFC*RSFCP
SM1=1.-SM
PBOTFC=1.
!
!-------------FIRST ADJUSTMENT OF TEMPERATURE PROFILE-------------------
!!
! SUMDT=0.
! SUMDP=0.
!!
! DO L=LTOP,LB
! SUMDT=(TK(L)-TREFK(L))*DPRS(L)+SUMDT
! SUMDP=SUMDP+DPRS(L)
! ENDDO
!!
! TCORR=SUMDT/SUMDP
!!
! DO L=LTOP,LB
! TREFK(L)=TREFK(L)+TCORR
! ENDDO
!!
!-----------------------------------------------------------------------
!--------------- ITERATION LOOP FOR CLOUD EFFICIENCY -------------------
!-----------------------------------------------------------------------
!
cloud_efficiency : DO ITREFI=1,ITREFI_MAX
!
!-----------------------------------------------------------------------
DSPBK=((EFI-EFIMN)*SLOPBS+DSPBSS*PBOTFC)*SM &
& +((EFI-EFIMN)*SLOPBL+DSPBSL*PBOTFC)*SM1
DSP0K=((EFI-EFIMN)*SLOP0S+DSP0SS*PBOTFC)*SM &
& +((EFI-EFIMN)*SLOP0L+DSP0SL*PBOTFC)*SM1
DSPTK=((EFI-EFIMN)*SLOPTS+DSPTSS*PBOTFC)*SM &
& +((EFI-EFIMN)*SLOPTL+DSPTSL*PBOTFC)*SM1
!
!-----------------------------------------------------------------------
!
DO L=LTOP,LB
!
!***
!*** SATURATION PRESSURE DIFFERENCE
!***
IF(DEPWL>=DEPTH)THEN
IF(L<L0)THEN
DSP=((PK0-PK(L))*DSPTK+(PK(L)-PKT)*DSP0K)/(PK0-PKT)
ELSE
DSP=((PKB-PK(L))*DSP0K+(PK(L)-PK0)*DSPBK)/(PKB-PK0)
ENDIF
ELSE
DSP=DSP0K
IF(L<L0)THEN
DSP=((PK0-PK(L))*DSPTK+(PK(L)-PKT)*DSP0K)/(PK0-PKT)
ENDIF
ENDIF
!***
!*** HUMIDITY PROFILE
!***
IF(PK(L)>PQM)THEN
PSK(L)=PK(L)+DSP
APESK(L)=(1.E5/PSK(L))**CAPA
THSK(L)=TREFK(L)*APEK(L)
QREFK(L)=PQ0/PSK(L)*EXP(A2*(THSK(L)-A3*APESK(L)) &
& /(THSK(L)-A4*APESK(L)))
ELSE
QREFK(L)=QK(L)
ENDIF
!
ENDDO
!-----------------------------------------------------------------------
!***
!*** ENTHALPY CONSERVATION INTEGRAL
!***
!-----------------------------------------------------------------------
enthalpy_conservation : DO ITER=1,2