      SUBROUTINE CNSBND(SVI,QRVN,RSN,TEMPN,QRC,HLST,DHDT,QR, &
                        DRDT,ZH,PRES,DT,ILGA,LEVA)
!-----------------------------------------------------------------------
!     PURPOSE:
!     --------
!     CALCULATES SUPERSATURATION FOR GIVEN CLOUD WATER CONTENT BASED
!     ON CONSERVATION OF ENERGY AND WATER.
!
!     HISTORY:
!     --------
!     * JUN 20/2008 - K.VONSALZEN   ADD OPTION TO USE LIQUID WATER
!                                   STATIC ENERGY IN ADDITION TO MOIST
!                                   STATIC ENERGY.
!     * AUG 25/2006 - K.VONSALZEN   NEW.
!
!-----------------------------------------------------------------------
!
      USE CNPARM
      USE SDPHYS
      USE FPDEF
!
      IMPLICIT REAL (A-H,O-Z), INTEGER (I-N)
!
      INTEGER, INTENT(IN) :: ILGA,LEVA
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA) :: QR,DRDT,HLST,DHDT,ZH, &
                                                PRES,QRC,DT
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA) :: RSN,TEMPN,QRVN,SVI
      REAL, ALLOCATABLE, DIMENSION(:,:) :: RELH,TMP1,TMP2,TMP3,ESW,QRCT
      REAL, PARAMETER :: YEPSM=0.999
!
!-----------------------------------------------------------------------
!     * ALLOCATE WORK ARRAYS.
!
      ALLOCATE(RELH(ILGA,LEVA))
      ALLOCATE(TMP1(ILGA,LEVA))
      ALLOCATE(TMP2(ILGA,LEVA))
      ALLOCATE(TMP3(ILGA,LEVA))
      ALLOCATE(ESW (ILGA,LEVA))
      ALLOCATE(QRCT(ILGA,LEVA))
!
!     * MAKE SURE CLOUD WATER MIXING RATIO DOES NOT EXCEED
!     * TOTAL WATER MIXING RATIO.
!
      QRCT=QRC
      TMP1=QR+DRDT*DT
      WHERE ( QRCT >= TMP1 )
        QRCT=YEPSM*TMP1
      ENDWHERE
!
!     * UPDATE WATER VAPOUR AND TEMPERATURE. EITHER MOIST STATIC
!     * ENERGY OR LIQUID/ICE WATER STATIC ENERGY IS USED, DEPENDING
!     * ON THE MODEL INPUT.
!
      QRVN=QR+DRDT*DT-QRCT
      IF ( KNORM ) THEN
        TEMPN=(HLST+DHDT*DT-RL*QRVN-GRAV*ZH)/CPRES
      ELSE
        TEMPN=(HLST+DHDT*DT+RL*QRCT-GRAV*ZH)/CPRES
      ENDIF
!
!     * UPDATE SATURATION MIXING RATIO.
!
      IF ( KSATF ) THEN
        IF ( KDBL ) THEN
          TMP3=RW1+RW2/TEMPN
          TMP1=EXP(TMP3)
          TMP3=RW3
          TMP2=TEMPN**TMP3
        ELSE
          TMP3=RW1+RW2/TEMPN
          TMP1=EXP(TMP3)
          TMP3=RW3
          TMP2=TEMPN**TMP3
        ENDIF
        ESW=1.E+02*TMP1*TMP2
      ELSE
        DO L=1,LEVA
        DO IL=1,ILGA
          ESW(IL,L)=1.E+02*EXP(PPA-PPB/TEMPN(IL,L))
        ENDDO
        ENDDO
      ENDIF
      WHERE ( ABS(PRES-ESW) > YSMALL )
        RSN=EPS1*ESW/(PRES-ESW)
      ELSEWHERE
        RSN=YLARGE
      ENDWHERE
!
!     * IMPLIED RELATIVE HUMIDITY AND SUPERSATURATION FOR GIVEN
!     * TEMPERATURE AND WATER VAPOUR.
!
      WHERE ( ABS(RSN-YLARGE) > YSMALL )
        RELH=QRVN/RSN*(1.+RSN/EPS1)/(1.+QRVN/EPS1)
      ELSEWHERE
        RELH=0.
      ENDWHERE
      SVI=RELH-1.
!
!     * DEALLOCATE WORK ARRAYS.
!
      DEALLOCATE(RELH)
      DEALLOCATE(TMP1)
      DEALLOCATE(TMP2)
      DEALLOCATE(TMP3)
      DEALLOCATE(ESW)
      DEALLOCATE(QRCT)
!
      END SUBROUTINE CNSBND
