!--------------------------------------------------------------------------------------------------
!  DOXYGEN
!> @brief DRY CONVECTIVE ADJUSTMENT
!> @details DRY CONVECTIVE ADJUSTMENT
!> @author ORIGINATOR - ????? 
!> @date ??-??-?? \n
!> @author LUCCI 
!> @date 18-03-20 \n
!> @version V1.1.0
!> @details MODERNIZATION OF THE CODE, INCLUDING:
!!                      * F77 TO F90/F95
!!                      * INDENTATION & UNIFORMIZATION CODE
!!                      * REPLACEMENT OF COMMONS BLOCK FOR MODULES
!!                      * DOCUMENTATION WITH DOXYGEN
!!                      * OPENMP FUNCTIONALITY 
!<
!> @details <b>Use Module:</b>
!! @arg @c CTLBLK 
!! @arg @c DYNAM
!! @arg @c F77KINDS
!! @arg @c PARMETA
!! @arg @c VRBLS
!> @details <b>Driver:</b> 
!<
!> @details <b>Calls:</b>
!! @arg @c BOCOHMPI
!--------------------------------------------------------------------------------------------------
    SUBROUTINE DCONV
!--------------------------------------------------------------------------------------------------
! SUBROUTINE DCONV
!
! SUBPROGRAM: DCONV - DRY CONVECTIVE ADJUSTMENT
! PROGRAMMER: ?????
! ORG: W/NP2 
! DATE: ??-??-??
!
! ABSTRACT:
! DRY CONVECTIVE ADJUSTMENT
!
! PROGRAM HISTORY LOG:
! ??-??-??  ?????     - ORIGINATOR
! 18-03-20  LUCCI     - MODERNIZATION OF THE CODE, INCLUDING:
!                       * F77 TO F90/F95
!                       * INDENTATION & UNIFORMIZATION CODE
!                       * REPLACEMENT OF COMMONS BLOCK FOR MODULES
!                       * DOCUMENTATION WITH DOXYGEN
!                       * OPENMP FUNCTIONALITY 
!
! INPUT ARGUMENT LIST:
! NONE
!
! OUTPUT ARGUMENT LIST:
! NONE
!
! INPUT/OUTPUT ARGUMENT LIST:
! NONE 
!
! USE MODULES: CTLBLK
!              DYNAM
!              F77KINDS
!              PARMETA
!              VRBLS
!  
! DRIVER     : -----
!
! CALLS      : BOCOHMPI           
!--------------------------------------------------------------------------------------------------
    USE CTLBLK
    USE DYNAM
    USE F77KINDS
    USE PARMETA
    USE VRBLS
!
    LOGICAL(KIND=L4)                                                                            ::&
    & LNOCONV
!
    REAL   (KIND=R4)    , DIMENSION (LM)                                                        ::&
    & GAM
!
    REAL   (KIND=R4)    , DIMENSION (0:IM+1, 0:JM+1)                                            ::&
    & PDSL  
!-------------------------
! PREPARATORY CALCULATIONS
!-------------------------
    IF (SIGMA) THEN
        DO I=0,IM+1
            DO J=0,JM+1
                PDSL(I,J) = PD(I,J)
            END DO
        END DO
    ELSE
        DO I=0,IM+1
            DO J=0,JM+1
                PDSL(I,J) = RES(I,J) * PD(I,J)
            END DO
        END DO
    END IF
!
    DO I=1,IM
        DO J=1,JM
            DO L=2,LM
                PRES   = PT   +   ETA(L) * PDSL(I,J)
                GAM(L) = 0.29 * DAETA(L) * PDSL(I,J) / PRES
            END DO

! 
            LNOCONV = .TRUE.
!
            DO L=2,LM
                ATL  = (T(I,J,L) + T(I,J,L-1)) * 0.5
                DTL  =  T(I,J,L) - T(I,J,L-1)
!
                GAMA = GAM(L) * ATL
!
                IF (DTL > GAMA) THEN
                    LNOCONV = .FALSE.
                    GAMA05  = GAMA * 0.5
!
                    T(I,J,L-1) = ATL - GAMA05
                    T(I,J,L  ) = ATL + GAMA05
                END IF
!
            END DO
!
            IF (LNOCONV) EXIT
!
        END DO
!
    END DO
!
    CALL BOCOHMPI(T,LM)
!
    END SUBROUTINE DCONV
