anchor.diff:                        DQDT,DQIDT,DQCDT,DQRDT,DQSDT,DTDT,   &
                         RAINCV,PRATEC,NCA,                   &
                         warm_rain,qi_flag,qs_flag,           &
  -                      ids,ide, jds,jde, kds,kde,           & 
  +                      ids,ide, jds,jde, kds,kde,           &
                         ims,ime, jms,jme, kms,kme,           &
                         its,ite, jts,jte, kts,kte            )
   !-----------------------------------------------------------
  
positive.code:               ENDIF
              ENDIF
  
  !......     QSTEN STORES GRAUPEL TENDENCY IF IT EXISTS, OTHERISE SNOW (V2)     
  
              IF( PRESENT( RQICUTEN ) .AND. qi_flag )THEN
                DO K=kts,kte
  
negative.code:               QFXTOP(NK-1)=QFXTOP(NK-1)-QFXBOT(NK)
              ENDIF
    494     CONTINUE
  !
  !...UPDATE THE THETA AND QV VALUES AT EACH LEVEL..
  !
            DO 492 NK=1,LTOP
              THPA(NK)=THPA(NK)+(THFXBOT(NK)+UDR(NK)*THTAU(NK)+DDR(NK)*     &
                       THTAD(NK)+THFXTOP(NK)-(UER(NK)-DER(NK))*THTA0(NK))* &
                       DTIME*EMSD(NK)
              QPA(NK)=QPA(NK)+(QFXBOT(NK)+UDR(NK)*QDT(NK)+DDR(NK)*QD(NK)+   &
                      QFXTOP(NK)-(UER(NK)-DER(NK))*Q0(NK))*DTIME*EMSD(NK)
  
    492     CONTINUE
    495   CONTINUE
          DO 498 NK=1,LTOP
            THTAG(NK)=THPA(NK)
            QG(NK)=QPA(NK)
    498   CONTINUE
  !
  !...CHECK TO SEE IF MIXING RATIO DIPS BELOW ZERO ANYWHERE;  IF SO,
  !...BORROW MOISTURE FROM ADJACENT LAYERS TO BRING IT BACK UP ABOVE ZERO.
  !
          DO 499 NK=1,LTOP
            IF(QG(NK).LT.0.)THEN
              IF(NK.EQ.1)THEN
                stop ( 'module_cu_kf.F: problem with kf scheme:  qg = 0 at the surface' )
              ENDIF
              NK1=NK+1
              IF(NK.EQ.LTOP)NK1=KLCL
              TMA=QG(NK1)*EMS(NK1)
              TMB=QG(NK-1)*EMS(NK-1)
              TMM=(QG(NK)-1.E-9)*EMS(NK)
              BCOEFF=-TMM/((TMA*TMA)/TMB+TMB)
              ACOEFF=BCOEFF*TMA/TMB
              TMB=TMB*(1.-BCOEFF)
              TMA=TMA*(1.-ACOEFF)
              IF(NK.EQ.LTOP)THEN
                QVDIFF=(QG(NK1)-TMA*EMSD(NK1))*100./QG(NK1)
                IF(ABS(QVDIFF).GT.1.)THEN
              PRINT *,'--WARNING-- CLOUD BASE WATER VAPOR CHANGES BY ',    &
              QVDIFF,                                                      &
               ' PERCENT WHEN MOISTURE IS BORROWED TO PREVENT NEG VALUES', &
               ' IN KAIN-FRITSCH'
                ENDIF
              ENDIF
              QG(NK)=1.E-9
              QG(NK1)=TMA*EMSD(NK1)
              QG(NK-1)=TMB*EMSD(NK-1)
            ENDIF
    499   CONTINUE
          TOPOMG=(UDR(LTOP)-UER(LTOP))*DP(LTOP)*EMSD(LTOP)
          IF(ABS(TOPOMG-OMG(LTOP)).GT.1.E-3)THEN
  !       WRITE(98,*)'ERROR:  MASS DOES NOT BALANCE IN KF SCHEME;'
  !    * ,'TOPOMG, OMG =',TOPOMG,OMG(LTOP)
          WRITE(6,*)'ERROR:  MASS DOES NOT BALANCE IN KF SCHEME;'        &
         ,'TOPOMG, OMG =',TOPOMG,OMG(LTOP)
            ISTOP=1
            GOTO 265
          ENDIF
  !
  !...CONVERT THETA TO T...
  !
  ! PAY ATTENTION ...
  !
          DO 230 NK=1,LTOP
            EXN(NK)=(P00/P0(NK))**(0.2854*(1.-0.28*QG(NK)))
            TG(NK)=THTAG(NK)/EXN(NK)
            TVG(NK)=TG(NK)*(1.+0.608*QG(NK))
    230   CONTINUE
  !
  !*******************************************************************
  !                                                                  *
  !     COMPUTE NEW CLOUD AND CHANGE IN AVAILABLE BUOYANT ENERGY.    *
  !                                                                  *
  !*******************************************************************
  !
  !...THE FOLLOWING COMPUTATIONS ARE SIMILAR TO THAT FOR UPDRAFT
  !
          THMIX=0.
          QMIX=0.
          PMIX=0.
          DO 217 NK=LC,KPBL
            ROCPQ=0.2854*(1.-0.28*QG(NK))
            THMIX=THMIX+DP(NK)*TG(NK)*(P00/P0(NK))**ROCPQ
            QMIX=QMIX+DP(NK)*QG(NK)
    217   PMIX=PMIX+DP(NK)*P0(NK)
          THMIX=THMIX/DPTHMX
          QMIX=QMIX/DPTHMX
          PMIX=PMIX/DPTHMX
          ROCPQ=0.2854*(1.-0.28*QMIX)
          TMIX=THMIX*(PMIX/P00)**ROCPQ
          ES=ALIQ*EXP((TMIX*BLIQ-CLIQ)/(TMIX-DLIQ))
          QS=EP2*ES/(PMIX-ES)
  !
  !...REMOVE SUPERSATURATION FOR DIAGNOSTIC PURPOSES, IF NECESSARY...
  !
          IF(QMIX.GT.QS)THEN
            RL=XLV0-XLV1*TMIX
            CPM=CP*(1.+0.887*QMIX)
            DSSDT=QS*(CLIQ-BLIQ*DLIQ)/((TMIX-DLIQ)*(TMIX-DLIQ))
            DQ=(QMIX-QS)/(1.+RL*DSSDT/CPM)
            TMIX=TMIX+RL/CP*DQ
            QMIX=QMIX-DQ
            ROCPQ=0.2854*(1.-0.28*QMIX)
            THMIX=TMIX*(P00/PMIX)**ROCPQ
            TLCL=TMIX
            PLCL=PMIX
          ELSE
            QMIX=AMAX1(QMIX,0.)
            EMIX=QMIX*PMIX/(EP2+QMIX)
            TLOG=ALOG(EMIX/ALIQ)
            TDPT=(CLIQ-DLIQ*TLOG)/(BLIQ-TLOG)
            TLCL=TDPT-(.212+1.571E-3*(TDPT-T00)-4.36E-4*(TMIX-T00))*(TMIX-  &
                 TDPT)
            TLCL=AMIN1(TLCL,TMIX)
            CPORQ=1./ROCPQ
            PLCL=P00*(TLCL/THMIX)**CPORQ
          ENDIF
          TVLCL=TLCL*(1.+0.608*QMIX)
          DO 235 NK=LC,KL
            KLCL=NK
    235   IF(PLCL.GE.P0(NK))GOTO 240
    240   K=KLCL-1
          DLP=ALOG(PLCL/P0(K))/ALOG(P0(KLCL)/P0(K))
  !
  !...ESTIMATE ENVIRONMENTAL TEMPERATURE AND MIXING RATIO AT THE LCL...
  !
          TENV=TG(K)+(TG(KLCL)-TG(K))*DLP
          QENV=QG(K)+(QG(KLCL)-QG(K))*DLP
          TVEN=TENV*(1.+0.608*QENV)
          TVBAR=0.5*(TVG(K)+TVEN)
  !        ZLCL=Z0(K)+R*TVBAR*ALOG(P0(K)/PLCL)/G
          ZLCL=Z0(K)+(Z0(KLCL)-Z0(K))*DLP
          TVAVG=0.5*(TVEN+TG(KLCL)*(1.+0.608*QG(KLCL)))
          PLCL=P0(KLCL)*EXP(G/(R*TVAVG)*(Z0(KLCL)-ZLCL))
          THETEU(K)=TMIX*(1.E5/PMIX)**(0.2854*(1.-0.28*QMIX))*            &
                    EXP((3374.6525/TLCL-2.5403)*QMIX*(1.+0.81*QMIX))
          ES=ALIQ*EXP((TENV*BLIQ-CLIQ)/(TENV-DLIQ))
          QESE=EP2*ES/(PLCL-ES)
          THTESG(K)=TENV*(1.E5/PLCL)**(0.2854*(1.-0.28*QESE))*            &
                    EXP((3374.6525/TENV-2.5403)*QESE*(1.+0.81*QESE))
  !
  !...COMPUTE ADJUSTED ABE(ABEG).
  !
          ABEG=0.
          THTUDL=THETEU(K)
          DO 245 NK=K,LTOPM1
            NK1=NK+1
            ES=ALIQ*EXP((TG(NK1)*BLIQ-CLIQ)/(TG(NK1)-DLIQ))
            QESE=EP2*ES/(P0(NK1)-ES)
            THTESG(NK1)=TG(NK1)*(1.E5/P0(NK1))**(0.2854*(1.-0.28*QESE))*    &
                        EXP((3374.6525/TG(NK1)-2.5403)*QESE*(1.+0.81*QESE)  &
                        )
  !         DZZ=CVMGT(Z0(KLCL)-ZLCL,DZA(NK),NK.EQ.K)
            IF(NK.EQ.K)THEN
              DZZ=Z0(KLCL)-ZLCL
            ELSE
              DZZ=DZA(NK)
            ENDIF
            BE=((2.*THTUDL)/(THTESG(NK1)+THTESG(NK))-1.)*DZZ
    245   IF(BE.GT.0.)ABEG=ABEG+BE*G
  !
  !...ASSUME AT LEAST 90% OF CAPE (ABE) IS REMOVED BY CONVECTION DURING
  !...THE PERIOD TIMEC...
  !
          IF(NOITR.EQ.1)THEN
  !        WRITE(98,1060)FABE
            GOTO 265
          ENDIF
          DABE=AMAX1(ABE-ABEG,0.1*ABE)
          FABE=ABEG/(ABE+1.E-8)
          IF(FABE.GT.1.)THEN
  !       WRITE(98,*)'UPDRAFT/DOWNDRAFT COUPLET INCREASES CAPE AT THIS '
  !    *,'GRID POINT; NO CONVECTION ALLOWED!'
            GOTO 325
          ENDIF
          IF(NCOUNT.NE.1)THEN
            DFDA=(FABE-FABEOLD)/(AINC-AINCOLD)
            IF(DFDA.GT.0.)THEN
              NOITR=1
              AINC=AINCOLD
              GOTO 255
            ENDIF
          ENDIF
          AINCOLD=AINC
          FABEOLD=FABE
          IF(AINC/AINCMX.GT.0.999.AND.FABE.GT.1.05-STAB)THEN
  !      WRITE(98,1055)FABE
            GOTO 265
          ENDIF
          IF(FABE.LE.1.05-STAB.AND.FABE.GE.0.95-STAB)GOTO 265
          IF(NCOUNT.GT.10)THEN
  !       WRITE(98,1060)FABE
            GOTO 265
          ENDIF
  !
  !...IF MORE THAN 10% OF THE ORIGINAL CAPE REMAINS, INCREASE THE
  !...CONVECTIVE MASS FLUX BY THE FACTOR AINC:
  !
          IF(FABE.EQ.0.)THEN
            AINC=AINC*0.5
          ELSE
            AINC=AINC*STAB*ABE/(DABE+1.E-8)
          ENDIF
    255   AINC=AMIN1(AINCMX,AINC)
  !...IF AINC BECOMES VERY SMALL, EFFECTS OF CONVECTION
  !...WILL BE MINIMAL SO JUST IGNORE IT...
          IF(AINC.LT.0.05)GOTO 325
  !       AINC=AMAX1(AINC,0.05)
          TDER=TDER2*AINC
          PPTFLX=PPTFL2*AINC
  !     WRITE(98,1080)LFS,LDB,LDT,TIMEC,NSTEP,NCOUNT,FABEOLD,AINCOLD
          DO 260 NK=1,LTOP
            UMF(NK)=UMF2(NK)*AINC
            DMF(NK)=DMF2(NK)*AINC
            DETLQ(NK)=DETLQ2(NK)*AINC
            DETIC(NK)=DETIC2(NK)*AINC
            UDR(NK)=UDR2(NK)*AINC
            UER(NK)=UER2(NK)*AINC
            DER(NK)=DER2(NK)*AINC
            DDR(NK)=DDR2(NK)*AINC
    260   CONTINUE
  !
  !...GO BACK UP FOR ANOTHER ITERATION...
  !
          GOTO 175
    265   CONTINUE
  !
  !...CLEAN THINGS UP, CALCULATE CONVECTIVE FEEDBACK TENDENCIES FOR THIS
  !...GRID POINT...
  !
  !...COMPUTE HYDROMETEOR TENDENCIES AS IS DONE FOR T, QV...
  !
  !...FRC2 IS THE FRACTION OF TOTAL CONDENSATE
  !...GENERATED THAT GOES INTO PRECIPITIATION
          FRC2=PPTFLX/(CPR*AINC)
          DO 270 NK=1,LTOP
            QLPA(NK)=QL0(NK)
            QIPA(NK)=QI0(NK)
            QRPA(NK)=QR0(NK)
            QSPA(NK)=QS0(NK)
            RAINFB(NK)=PPTLIQ(NK)*AINC*FBFRC*FRC2
            SNOWFB(NK)=PPTICE(NK)*AINC*FBFRC*FRC2
    270   CONTINUE
          DO 290 NTC=1,NSTEP
  !
  !...ASSIGN HYDROMETEORS CONCENTRATIONS AT THE TOP AND BOTTOM OF EACH
  !...LAYER BASED ON THE SIGN OF OMEGA...
  !
            DO 275 NK=1,LTOP
              QLFXIN(NK)=0.
              QLFXOUT(NK)=0.
              QIFXIN(NK)=0.
              QIFXOUT(NK)=0.
              QRFXIN(NK)=0.
              QRFXOUT(NK)=0.
              QSFXIN(NK)=0.
              QSFXOUT(NK)=0.
    275     CONTINUE
            DO 280 NK=2,LTOP
              IF(OMG(NK).LE.0.)THEN
                QLFXIN(NK)=-FXM(NK)*QLPA(NK-1)
                QIFXIN(NK)=-FXM(NK)*QIPA(NK-1)
                QRFXIN(NK)=-FXM(NK)*QRPA(NK-1)
                QSFXIN(NK)=-FXM(NK)*QSPA(NK-1)
                QLFXOUT(NK-1)=QLFXOUT(NK-1)+QLFXIN(NK)
                QIFXOUT(NK-1)=QIFXOUT(NK-1)+QIFXIN(NK)
                QRFXOUT(NK-1)=QRFXOUT(NK-1)+QRFXIN(NK)
                QSFXOUT(NK-1)=QSFXOUT(NK-1)+QSFXIN(NK)
              ELSE
                QLFXOUT(NK)=FXM(NK)*QLPA(NK)
                QIFXOUT(NK)=FXM(NK)*QIPA(NK)
                QRFXOUT(NK)=FXM(NK)*QRPA(NK)
                QSFXOUT(NK)=FXM(NK)*QSPA(NK)
                QLFXIN(NK-1)=QLFXIN(NK-1)+QLFXOUT(NK)
                QIFXIN(NK-1)=QIFXIN(NK-1)+QIFXOUT(NK)
                QRFXIN(NK-1)=QRFXIN(NK-1)+QRFXOUT(NK)
                QSFXIN(NK-1)=QSFXIN(NK-1)+QSFXOUT(NK)
              ENDIF
    280     CONTINUE
  !
  !...UPDATE THE HYDROMETEOR CONCENTRATION VALUES AT EACH LEVEL...
  !
            DO 285 NK=1,LTOP
              QLPA(NK)=QLPA(NK)+(QLFXIN(NK)+DETLQ(NK)-QLFXOUT(NK))*DTIME*  &
                       EMSD(NK)
              QIPA(NK)=QIPA(NK)+(QIFXIN(NK)+DETIC(NK)-QIFXOUT(NK))*DTIME*  &
                       EMSD(NK)
              QRPA(NK)=QRPA(NK)+(QRFXIN(NK)+QLQOUT(NK)*UDR(NK)-QRFXOUT(NK) &
                       +RAINFB(NK))*DTIME*EMSD(NK)
              QSPA(NK)=QSPA(NK)+(QSFXIN(NK)+QICOUT(NK)*UDR(NK)-QSFXOUT(NK) &
                       +SNOWFB(NK))*DTIME*EMSD(NK)
    285     CONTINUE
    290   CONTINUE
          DO 295 NK=1,LTOP
            QLG(NK)=QLPA(NK)
            QIG(NK)=QIPA(NK)
            QRG(NK)=QRPA(NK)
            QSG(NK)=QSPA(NK)
    295   CONTINUE
  !     WRITE(98,1080)LFS,LDB,LDT,TIMEC,NSTEP,NCOUNT,FABE,AINC
  !
  !...SEND FINAL PARAMETERIZED VALUES TO OUTPUT FILES...
  !
          IF(ISTOP.EQ.1)THEN
          WRITE(6,1070)'  P  ','   DP ',' DT K/D ',' DR K/D ','   OMG  ',  &
        ' DOMGDP ','   UMF  ','   UER  ','   UDR  ','   DMF  ','   DER  '  &
        ,'   DDR  ','   EMS  ','    W0  ','  DETLQ ',' DETIC '
            DO 300 K=LTOP,1,-1
              DTT=(TG(K)-T0(K))*86400./TIMEC
              RL=XLV0-XLV1*TG(K)
              DR=-(QG(K)-Q0(K))*RL*86400./(TIMEC*CP)
              UDFRC=UDR(K)*TIMEC*EMSD(K)
              UEFRC=UER(K)*TIMEC*EMSD(K)
              DDFRC=DDR(K)*TIMEC*EMSD(K)
              DEFRC=-DER(K)*TIMEC*EMSD(K)
              WRITE (6,1075)P0(K)/100.,DP(K)/100.,DTT,DR,OMG(K),DOMGDP(K)* &
                            1.E4,UMF(K)/1.E6,UEFRC,UDFRC,DMF(K)/1.E6,DEFRC &
                            ,DDFRC,EMS(K)/1.E11,W0AVG1D(K)*1.E2,DETLQ(K) &
                            *TIMEC*EMSD(K)*1.E3,DETIC(K)*TIMEC*EMSD(K)*    &
                            1.E3
    300     CONTINUE
          WRITE(6,1085)'K','P','Z','T0','TG','DT','TU','TD','Q0','QG',     &
                    'DQ','QU','QD','QLG','QIG','QRG','QSG','RH0','RHG'
            DO 305 K=KX,1,-1
              DTT=TG(K)-T0(K)
              TUC=TU(K)-T00
              IF(K.LT.LC.OR.K.GT.LTOP)TUC=0.
              TDC=TZ(K)-T00
              IF((K.LT.LDB.OR.K.GT.LDT).AND.K.NE.LFS)TDC=0.
              ES=ALIQ*EXP((BLIQ*TG(K)-CLIQ)/(TG(K)-DLIQ))
              QGS=ES*EP2/(P0(K)-ES)
              RH0=Q0(K)/QES(K)
              RHG=QG(K)/QGS
              WRITE (6,1090)K,P0(K)/100.,Z0(K),T0(K)-T00,TG(K)-T00,DTT,TUC &
                            ,TDC,Q0(K)*1000.,QG(K)*1000.,(QG(K)-Q0(K))*    &
                            1000.,QU(K)*1000.,QD(K)*1000.,QLG(K)*1000.,    &
                            QIG(K)*1000.,QRG(K)*1000.,QSG(K)*1000.,RH0,RHG
    305     CONTINUE
  !
  !...IF CALCULATIONS ABOVE SHOW AN ERROR IN THE MASS BUDGET, PRINT OUT A
  !...TO BE USED LATER FOR DIAGNOSTIC PURPOSES, THEN ABORT RUN...
  !
            IF(ISTOP.EQ.1)THEN
              DO 310 K=1,KX
                WRITE ( * , * )                         &
                              Z0(K),P0(K)/100.,T0(K)-273.16,Q0(K)*1000.,   &
                              U0(K),V0(K),DP(K)/100.,W0AVG1D(K)
  !               CALL wrf_message ( TRIM( wrf_err_message ) )
    310       CONTINUE
              stop ( 'module_cu_kf.F: KAIN-FRITSCH' )
            ENDIF
          ENDIF
          CNDTNF=(1.-EQFRC(LFS))*(QLIQ(LFS)+QICE(LFS))*DMF(LFS)
  !     WRITE(98,1095)CPR*AINC,TDER+PPTFLX+CNDTNF
  !
  !  EVALUATE MOISTURE BUDGET...
  !
          QINIT=0.
          QFNL=0.
          DPT=0.
          DO 315 NK=1,LTOP
            DPT=DPT+DP(NK)
            QINIT=QINIT+Q0(NK)*EMS(NK)
            QFNL=QFNL+QG(NK)*EMS(NK)
            QFNL=QFNL+(QLG(NK)+QIG(NK)+QRG(NK)+QSG(NK))*EMS(NK)
    315   CONTINUE
          QFNL=QFNL+PPTFLX*TIMEC*(1.-FBFRC)
          ERR2=(QFNL-QINIT)*100./QINIT
  !     WRITE(98,1110)QINIT,QFNL,ERR2
  !        IF(ABS(ERR2).GT.0.05)STOP 'QVERR'
          IF(ABS(ERR2).GT.0.05) stop 'module_cu_kf.F: QVERR'
          RELERR=ERR2*QINIT/(PPTFLX*TIMEC+1.E-10)
  !     WRITE(98,1120)RELERR
  !     WRITE(98,*)'TDER, CPR, USR, TRPPT =',
  !    *TDER,CPR*AINC,USR*AINC,TRPPT*AINC
  !
  !...FEEDBACK TO RESOLVABLE SCALE TENDENCIES.
  !
  !...IF THE ADVECTIVE TIME PERIOD (TADVEC) IS LESS THAN SPECIFIED MINIMUM
  !...TIMEC, ALLOW FEEDBACK TO OCCUR ONLY DURING TADVEC...
  !
          IF(TADVEC.LT.TIMEC)NIC=NINT(TADVEC/DT)
          NCA(I,J)=FLOAT(NIC)*DT
          DO 320 K=1,KX
  !         IF(IMOIST.NE.2)THEN
  !
  !...IF HYDROMETEORS ARE NOT ALLOWED, THEY MUST BE EVAPORATED OR SUBLIMAT
  !...AND FED BACK AS VAPOR, ALONG WITH ASSOCIATED CHANGES IN TEMPERATURE.
  !...NOTE:  THIS WILL INTRODUCE CHANGES IN THE CONVECTIVE TEMPERATURE AND
  !...WATER VAPOR FEEDBACK TENDENCIES AND MAY LEAD TO SUPERSATURATED VALUE
  !...OF QG...
  !
  !           RLC=XLV0-XLV1*TG(K)
  !           RLS=XLS0-XLS1*TG(K)
  !           CPM=CP*(1.+0.887*QG(K))
  !           TG(K)=TG(K)-(RLC*(QLG(K)+QRG(K))+RLS*(QIG(K)+QSG(K)))/CPM
  !           QG(K)=QG(K)+(QLG(K)+QRG(K)+QIG(K)+QSG(K))
  !           DQCDT(K)=0.
  !           DQIDT(K)=0.
  !           DQRDT(K)=0.
  !           DQSDT(K)=0.
  !         ELSE
              IF(.NOT. qi_flag .and. warm_rain)THEN
  !
  !...IF ICE PHASE IS NOT ALLOWED, MELT ALL FROZEN HYDROMETEORS...
  !
                CPM=CP*(1.+0.887*QG(K))
                TG(K)=TG(K)-(QIG(K)+QSG(K))*RLF/CPM
                DQCDT(K)=(QLG(K)+QIG(K)-QL0(K)-QI0(K))/TIMEC
                DQIDT(K)=0.
                DQRDT(K)=(QRG(K)+QSG(K)-QR0(K)-QS0(K))/TIMEC
                DQSDT(K)=0.
              ELSEIF(.NOT. qi_flag .and. .not. warm_rain)THEN
  !
  !...IF ICE PHASE IS ALLOWED, BUT MIXED PHASE IS NOT, MELT FROZEN HYDROME
  !...BELOW THE MELTING LEVEL, FREEZE LIQUID WATER ABOVE THE MELTING LEVEL
  !
                CPM=CP*(1.+0.887*QG(K))
                IF(K.LE.ML)THEN
                  TG(K)=TG(K)-(QIG(K)+QSG(K))*RLF/CPM
                ELSEIF(K.GT.ML)THEN
                  TG(K)=TG(K)+(QLG(K)+QRG(K))*RLF/CPM
                ENDIF
                DQCDT(K)=(QLG(K)+QIG(K)-QL0(K)-QI0(K))/TIMEC
                DQIDT(K)=0.
                DQRDT(K)=(QRG(K)+QSG(K)-QR0(K)-QS0(K))/TIMEC
                DQSDT(K)=0.
              ELSEIF(qi_flag) THEN
  !
  !...IF MIXED PHASE HYDROMETEORS ARE ALLOWED, FEED BACK CONVECTIVE
  !...TENDENCY OF HYDROMETEORS DIRECTLY...
  !
                DQCDT(K)=(QLG(K)-QL0(K))/TIMEC
                DQIDT(K)=(QIG(K)-QI0(K))/TIMEC
                DQRDT(K)=(QRG(K)-QR0(K))/TIMEC
                IF (qs_flag ) THEN
                   DQSDT(K)=(QSG(K)-QS0(K))/TIMEC
                ELSE
                   DQIDT(K)=DQIDT(K)+(QSG(K)-QS0(K))/TIMEC
                ENDIF
              ELSE
                stop ( 'module_cu_kf: THIS COMBINATION OF IMOIST,  IICE NOT ALLOWED' )
              ENDIF
  !         ENDIF
            DTDT(K)=(TG(K)-T0(K))/TIMEC
            DQDT(K)=(QG(K)-Q0(K))/TIMEC
    320   CONTINUE
  
  ! RAINCV is in the unit of mm
  
          PRATEC(I,J)=PPTFLX*(1.-FBFRC)/DXSQ
          RAINCV(I,J)=DT*PRATEC(I,J)
          RNC=RAINCV(I,J)*NIC
  !        WRITE(98,909)RNC
   909     FORMAT(' CONVECTIVE RAINFALL =',F8.4,' CM')
  
    325 CONTINUE
  
  1000  FORMAT(' ',10A8)
  1005  FORMAT(' ',F6.0,2X,F7.4,2X,F7.3,1X,F7.4,2X,4(F6.3,2X),2(F7.3,1X))
  1010  FORMAT(' ',' VERTICAL VELOCITY IS NEGATIVE AT ',F4.0,' MB')
  1015   FORMAT(' ','ALL REMAINING MASS DETRAINS BELOW ',F4.0,' MB')
  1025   FORMAT(5X,' KLCL=',I2,' ZLCL=',F7.1,'M',                          &
          ' DTLCL=',F5.2,' LTOP=',I2,' P0(LTOP)=',-2PF5.1,'MB FRZ LV=',    &
          I2,' TMIX=',0PF4.1,1X,'PMIX=',-2PF6.1,' QMIX=',3PF5.1,           &
          ' CAPE=',0PF7.1)
  1030   FORMAT(' ',' P0(LET) = ',F6.1,' P0(LTOP) = ',F6.1,' VMFLCL =',    &
        E12.3,' PLCL =',F6.1,' WLCL =',F6.3,' CLDHGT =',                   &
        F8.1)
  1035  FORMAT(1X,'PEF(WS)=',F5.2,'(CB)=',F5.2,'LC,LET=',2I3,'WKL='        &
        ,F6.3,'VWS=',F5.2)
  1040          FORMAT(' ','PRECIP EFF = 100%, ENVIR CANNOT SUPPORT DOWND' &
        ,'RAFTS')
  !1045  FORMAT('NUMBER OF DOWNDRAFT ITERATIONS EXCEEDS 10...PPTFLX'       &
  !      ' IS DIFFERENT FROM THAT GIVEN BY PRECIP EFF RELATION')
  ! FLIC HAS TROUBLE WITH THIS ONE.
  1045  FORMAT('NUMBER OF DOWNDRAFT ITERATIONS EXCEEDS 10')
  1050  FORMAT(' ','LCOUNT= ',I3,' PPTFLX/CPR, PEFF= ',F6.3,1X,F6.3,       &
        'DMF(LFS)/UMF(LCL)= ',F6.3)
  1055     FORMAT(/'*** DEGREE OF STABILIZATION =',F6.3,', NO MORE MASS F' &
        ,'LUX IS ALLOWED')
  !1060     FORMAT(/' ITERATION DOES NOT CONVERGE TO GIVE THE SPECIFIED '  &
  !      'DEGREE OF STABILIZATION!  FABE= ',F7.4)
  1060  FORMAT(/' ITERATION DOES NOT CONVERGE.  FABE= ',F7.4)
   1070 FORMAT (16A8)
   1075 FORMAT (F8.2,3(F8.2),2(F8.3),F8.2,2F8.3,F8.2,6F8.3)
  1080   FORMAT(2X,'LFS,LDB,LDT =',3I3,' TIMEC, NSTEP=',F5.0,I3,           &
        'NCOUNT, FABE, AINC=',I2,1X,F6.3,F6.2)
   1085 FORMAT (A3,16A7,2A8)
   1090 FORMAT (I3,F7.2,F7.0,10F7.2,4F7.3,2F8.3)
  1095   FORMAT(' ','  PPT PRODUCTION RATE= ',F10.0,' TOTAL EVAP+PPT= ',   &
         F10.0)
  1105   FORMAT(' ','NET LATENT HEAT RELEASE =',E12.5,' ACTUAL HEATING =', &
         E12.5,' J/KG-S, DIFFERENCE = ',F9.3,'PERCENT')
  1110   FORMAT(' ','INITIAL WATER =',E12.5,' FINAL WATER =',E12.5,        &
         ' TOTAL WATER CHANGE =',F8.2,'PERCENT')
   1115 FORMAT (2X,F6.0,2X,F7.2,2X,F5.1,2X,F6.3,2(2X,F5.1),2X,F7.2,2X,F7.4 &
               )
  1120   FORMAT(' ','MOISTURE ERROR AS FUNCTION OF TOTAL PPT =',F9.3,      &
              'PERCENT')
  
     END SUBROUTINE KFPARA
  
  !-----------------------------------------------------------------------
     SUBROUTINE CONDLOAD(QLIQ,QICE,WTW,DZ,BOTERM,ENTERM,RATE,QNEWLQ,     &
                         QNEWIC,QLQOUT,QICOUT,G)
  !-----------------------------------------------------------------------
     IMPLICIT NONE
  !-----------------------------------------------------------------------
  !  9/18/88...THIS PRECIPITATION FALLOUT SCHEME IS BASED ON THE SCHEME US
  !  BY OGURA AND CHO (1973).  LIQUID WATER FALLOUT FROM A PARCEL IS CAL-
  !  CULATED USING THE EQUATION DQ=-RATE*Q*DT, BUT TO SIMULATE A QUASI-
  !  CONTINUOUS PROCESS, AND TO ELIMINATE A DEPENDENCY ON VERTICAL
  !  RESOLUTION THIS IS EXPRESSED AS Q=Q*EXP(-RATE*DZ).
  
        REAL, INTENT(IN   )   :: G
        REAL, INTENT(IN   )   :: DZ,BOTERM,ENTERM,RATE
  