     SUBROUTINE POPBOOLEAN(ldx)

      USE PARKIND1  ,ONLY : JPIM, JPRB
      USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

      USE YOEADBUFFER

      IMPLICIT NONE

      LOGICAL, INTENT(OUT) :: ldx

      INTEGER(KIND=JPIM) :: i_adl4ilbuf
      LOGICAL :: ll_adl4inlbuf

      REAL(KIND=JPRB) :: ZHOOK_HANDLE

      IF (LHOOK) CALL DR_HOOK('POPBOOLEAN',0,ZHOOK_HANDLE)

      IF (i_adl4ilbuf /= -1) THEN
         i_adl4ilbuf = -1
         ll_adl4inlbuf = .FALSE.
      ENDIF
      IF (adl4ibuf <= 1) THEN
         CALL POPBOOLEANARRAY(adl4buf, 512)
         adl4ibuf = 512
         ldx = adl4buf(512)
      ELSE
         adl4ibuf = adl4ibuf-1
         ldx = adl4buf(adl4ibuf)
      ENDIF

      IF (LHOOK) CALL DR_HOOK('POPBOOLEAN',1,ZHOOK_HANDLE)

     END SUBROUTINE POPBOOLEAN
