      SUBROUTINE NEW_OUTLET1(XF,YF,OUT_I,OUT_J,DEM,CATCH_FLAG,ROWS,COLS
     &,SX)

      ! THIS SUBROUTINE HELPS IN FINDING AN ALTERNATE OUTLET CELL IF THE
      ! PREVIOUSLY DETERMINED CATCHMENT-OUTLET CELL IS A SINK

      ! DESCRIPTION OF VARIABLES:

      ! DEM: CONTAINS DEM SURFACE ELEVATION (IN METERS) FOR EVERY GRID
      ! CELL. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! CATCH_FLAG: STORES THE LAKE CATCHMENT. SHOWS 1 FOR CATCHMENT
      ! CELLS AND 0 OTHERWISE. REMAINS UNCHANGED IN THIS SUBROUTINE

      ! ROWS,COLS: ROWS AND COLUMNS OF THE STUDY AREA. REMAINS
      ! UNMODIFIED IN THIS SUBROUTINE

      ! SX: CONSTANT

      ! OUT_I,OUT_J: STORES THE COORDINATES OF CATCHMENT OUTLET. REMAINS
      ! UNMODIFIED IN THIS SUBROUTINE

      ! XF,YF: 1D ARRAYS THAT STORE THE COORDINATES OF THE SURFACE
      ! ELEVATIONS OF THE CATCHMENT CELLS IN THE INCREASING ORDER OF
      ! THEIR RESPECTIVE ELEVATIONS. REMAINS UNMODIFIED IN THIS SUBROUTINE

      IMPLICIT NONE

      INTEGER :: SX,OUT_I,OUT_J,ROWS,COLS,XF(SX),YF(SX),NUM2,T,ICLOW,
     &VALC(9),II(9),JJ(9),A,B,NUM1,N,CATCH_FLAG(COLS,ROWS),COUNTX,X,Y

      DOUBLE PRECISION :: DEM(COLS,ROWS),VAL(9),NN,LOW

      NUM2=COUNT(XF.NE.0)
      T=1

      ! IF THE PRESENT OUTLET IS A SINK CELL, THEN A NEW OUTLET HAS TO
      ! BE CHOSEN. THIS IS DONE BY ASSUMING THAT THE NEW OUTLET MIGHT BE
      ! THE NEXT LOWEST CATCHMENT BOUNDARY CELL. THIS PROCESS IS
      ! REPEATED IN LOOP TILL A SUITABLE OUTLET IS LOCATED

      DO WHILE ((T.LE.NUM2).AND.(XF(T).GE.2).AND.(YF(T).GE.2).AND.
     &(XF(T).LE.COLS-1).AND.(YF(T).LE.ROWS-1))

      COUNTX=0
      A=XF(T)
      B=YF(T)

      ! NEIGHBOURHOOD OF THE OUTLET CELL

      II=(/A-1,A-1,A-1,A,A,A,A+1,A+1,A+1/)
      JJ=(/B-1,B,B+1,B-1,B,B+1,B-1,B,B+1/)

      DO 100 N=1,9
      X=II(N)
      Y=JJ(N)
      VAL(N)=DEM(X,Y) ! VALUES OF ELEVATION
      VALC(N)=CATCH_FLAG(X,Y) ! VALUES OF CATCH FLAG MATRIX
100   CONTINUE

      ICLOW=0
      LOW=999999
      DO 200 N=1,9
      IF (VAL(N).LT.LOW) THEN
              ICLOW=N
              LOW=VAL(N)
      END IF
200   CONTINUE

      IF (ICLOW.EQ.5) THEN ! IF YES, GO TO NEXT LOWEST BOUNDARY CELL
              T=T+1
      ELSE ! IF NOT, SCAN FOR A LOWER ELEVATIO CELL IN THE NEIGHBOURHOOD
              NN=DEM(XF(T),YF(T))

              DO 201 N=1,9
              A=II(N)
              B=JJ(N)
              IF ((NN.GT.VAL(N)).AND.(CATCH_FLAG(A,B).EQ.0)
     &.AND.(N.NE.5)) THEN
              COUNTX=COUNTX+1
              END IF
201           CONTINUE

              ! IF AN OUT OF CATCHMENT CELL WITH ELEVATION LOWER THAN
              ! THE OUTLET CELL EXIXTS THEN STOP THE SEARCH

              IF (COUNTX.GT.0) THEN
                      T=NUM2+1
                      OUT_I=II(5)
                      OUT_J=JJ(5)
              ELSE
                      T=T+1
              END IF
      END IF
      END DO

      RETURN

      END SUBROUTINE NEW_OUTLET1
