      SUBROUTINE LAKE_CHN_INC_OV1(NUC_I,NUC_J,SURF,DEM,ICE,CMARK,
     &SUMINC,LAKE_HT,LAKE_AR,LAKE_BASE,CHN_DEC,RUN_X,RUN_Y,RUN_LAK,
     &DRAIN_INCISE,LAKE_RED,RUNOFF,SDEP,SDEN,LAKE2RUN,LAK_NO_INC,ROWS,
     &COLS,SX,FLAG_OV)

      ! THIS SUBROUTINE SIMULATES LAKE DRAINAGE VIA CHANNEL INCISION

      ! DESCRIPTION OF VARIABLES:

      ! RUNOFF: CONTAINS RUNOFF MELTWATER (IN METERS) FOR EVERY GRID
      ! CELL. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! LAKE_RED: STORES THE HEIGHT OF WATER THAT HAS TO BE REDUCED FROM
      ! A LAKE AFTER IT HAS DRIANED VIA CHANNEL INCISION (IN EVERY
      ! TIMESTEP). REMAINS UNCHANGED IN THIS SUBROUTINE

      ! LAKE2RUN: STORES THE HEIGHT OF EXCESS LAKE WATER. THE EXCESS
      ! LAKE WATER IS A RESULT OF REDUCTION OF CHANNEL HEIGHT OF A LAKE
      ! DUE TO CHANNEL INCISION. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! LAK_NO_INC: STORES THE EXTENT OF THE LAKES THAT HAVE OVERFLOWN
      ! BUT WITHOUT CHANNEL INCISION. SHOWS 1 FOR LAKE PIXELS AND 0
      ! OTHERWISE. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! RUN_X: STORES THE RUNOFF THAT HAS BEEN TRANFERRED FROM A LAKE TO
      ! A NON-CREVASSED, NON-LAKE DEM CELL. THIS TRANSFER TAKES PLACE
      ! DURING LAKE OVERFLOW. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! RUN_Y: STORES THE RUNOFF THAT HAS BEEN TRANFERRED FROM A LAKE TO
      ! A CREVASSED, NON-LAKE DEM CELL. THIS TRANSFER TAKES PLACE
      ! DURING LAKE OVERFLOW. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! RUN_LAK: STORES THE RUNOFF THAT HAS BEEN TRANSFERRED FROM A LAKE
      ! TO ANOTHER EXISTING LAKE. THIS TRANSFER TAKES PLACE
      ! DURING LAKE OVERFLOW. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! DRAIN_INCISE: STORES THE LOCATION OF THE NUCLEI OF THE
      ! SGLS THAT DRAINED VIA CHANNEL-INCISION. SHOWS 1 FOR A LAKE THAT
      ! HAS STARTED TO DRAIN VIA CHANNEL INCISION AND 0 OTHERWISE. GETS
      ! MODIFIED IN THIS SUBROUTINE

      ! LAKE_HT: STORES THE REFERENCE LAKE HEIGHT. REMAINS UNCHANGED IN
      ! THIS SUBROUTINE

      ! LAKE_AR: STORES THE REFERENCE LAKE AREA. REMAINS UNCHANGED IN
      ! THIS SUBROUTINE

      ! LAKE_BASE: STORES THE REFERENCE LAKE VOLUME. REMAINS UNMODIFIED
      ! IN THIS SUBROUTINE

      ! CHN_DEC: STORES DEPTH OF SUPRAGLACIAL MELTWATER CHANNELS.
      ! REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! SDEN: CONTAINS SNOW DENSITY (IN kg/m^3) FOR EVERY GRID CELL.
      ! REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! SDEP: CONTAINS SNOW DEPTH (IN m) FOR EVERY GRID CELL.
      ! REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! NUC_I,NUC_J: 1-D ARRAY. STORES THE NUCLEI OF THE LAKES. UNMODIFIED
      ! IN THIS SUBROUTINE

      ! SURF: CONTAINS SURFACE HEIGHT (IN METERS) OF EVERY GRID CELL.
      ! REMAINS UNMODIFIED IN THIS SUBROUTINE

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

      ! ICE: CONTAINS ICE THICKNESS (IN METERS) FOR EVERY GRID CELL.
      ! REMAINS UNMODIFIED IN THIS SUBROUTINE

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

      ! CMARK: SHOWS 1 FOR CREVASSED CELL AND 0 FOR NON CREVASSED CELL.
      ! UPDATED EVERY TIMESTEP IN THE CREV_CELLS1.F SUBROUTINE. REMAINS
      ! UNMODIFIED IN THIS SUBROUTINE

      ! SUMINC: STORES THE VOLUME OF WATER THAT HAS OVERFLOWN FROM A
      ! LAKE DURING CHANNEL INCISION. REMAINS UNMODIFIED IN THIS
      ! SUBROUTNE

      ! RUNOFF: CONTAINS RUNOFF MELTWATER (IN METERS) FOR EVERY GRID
      ! CELL. REMAINS UNMODIFIED IN THIS SUBROUTINE

      ! SX: CONSTANT

      ! FLAG_OV: THIS MATRIX IDENTIFIES THE LAKE THAT HAS OVERFLOWN BUT
      ! WITHOUT CHANNEL INCISION. SHOWS 1 AT THE LOCATION OF THE LAKE
      ! NUCLEUS IF THE LAKE HAS OVERFLOWN AND 0 OTHERWISE. GETS
      ! MODIFIED IN THIS SUBROUTINE

      IMPLICIT NONE

      INTEGER :: SX,COLS,ROWS,MARK(COLS,ROWS),MARK1(COLS,ROWS),
     &PP,QQ,K1,K2,A1,B1,C11,XXX,NTHREADS,TID,CHUNK,ISTART,IEND,
     &K3,K4,CATCH_FLAG(COLS,ROWS),LAK_NO_INC(COLS,ROWS),XIND(SX),
     &YIND(SX),DEST_I,DEST_J,OUT_I,OUT_J,I,A,B,NUM11,CMARK(COLS,ROWS),
     &DRAIN_INCISE(COLS,ROWS),NUC_I(SX),NUC_J(SX),OMP_GET_MAX_THREADS,
     &OMP_GET_THREAD_NUM,I1,J1,NUM12,NUM13,FLAG_OV(COLS,ROWS)

      DOUBLE PRECISION :: DEM(COLS,ROWS),SURF(COLS,ROWS),
     &RUNOFF(COLS,ROWS),SDEP(COLS,ROWS),SDEN(COLS,ROWS),
     &LAKE2RUN(COLS,ROWS),LAKE_HT(COLS,ROWS),LAKE_AR(COLS,ROWS),
     &LAKE_BASE(COLS,ROWS),RUN_X(COLS,ROWS),RUN_Y(COLS,ROWS),
     &RUN_LAK(COLS,ROWS),LAKE_RED(COLS,ROWS),CHN_DEC(COLS,ROWS),
     &ICE(COLS,ROWS),SUMINC(COLS,ROWS),PATH_TOTAL,LAKE_DEPTH(COLS,ROWS)
     &,MELT(COLS,ROWS),RAIN(COLS,ROWS),WAT_LEV,SUMR

      K1=0
      K2=0
      K3=0
      K4=0
      LAKE_RED=0.
      LAKE2RUN=0.
      MARK1=0.
      MARK=0.
      XIND=0.
      YIND=0.
      CATCH_FLAG=0.
      LAKE_DEPTH=SURF-DEM
      PP=0
      QQ=0
      XXX=COUNT(NUC_I.NE.0) ! NUMBER OF NON-ZERO ENTITIES
      SUMR=0
      ISTART=1
      IEND=XXX

      DO 100 I=ISTART,IEND

      A=NUC_I(I)
      B=NUC_J(I)

      IF ((LAKE_DEPTH(A,B).GT.0).AND.(MARK1(A,B).NE.1)) THEN
              MARK=0.
              CATCH_FLAG=0.
              XIND=0.
              YIND=0.
              K1=0
              K2=0
              K3=0
              K4=0

              PP=A
              QQ=B

              ! DELINEATE THE LAKE

              CALL LAKE_DEL1(PP,QQ,MARK,MARK1,SURF,DEM,K1,K2,K3,K4,COLS
     &,ROWS)

              ! DISTRIBUTE LAKE RUNOFF EQUALLY ON ALL LAKE PIXELS

              CALL RUNOFF_DIST1(RUNOFF,MARK,PP,QQ,K1,K2,K3,K4,ROWS,COLS)

              ! DELINEATE CATCHMENT IF LAKE EXTENT IS POSITIVE

              IF (SUM(MARK).GT.0) THEN

                      ! DELINEATE LAKE CATCHMENT

                      K1=0
                      K2=0
                      K3=0
                      K4=0
                      CATCH_FLAG=0.

                      CALL LAKE_CATCHMENT1(DEM,PP,QQ,MARK,CMARK,
     &CATCH_FLAG,OUT_I,OUT_J,K1,K2,K3,K4,ROWS,COLS,SX,RUNOFF)

                      IF (SUM(CATCH_FLAG).EQ.0) THEN
                              WHERE (MARK.EQ.1)
                                      SURF=DEM
                                     ! 
                              END WHERE
                      END IF

                      ! LABEL THE FLOWPATH IF LAKE HAS REACHED TILL THE
                      ! CATCHMENT OUTLET'S LEVEL

                      WAT_LEV=SURF(PP,QQ)-DEM(OUT_I,OUT_J)

                      ! OVERFLOW WHEN THE WATER LEVEL HAS
                      ! REACHED THE LEVEL OF THE OUTLET CELL

                      IF ((WAT_LEV.GE.0)) THEN
                              CALL PATH_SEL_CHN_INC1(ROWS,COLS,
     &OUT_I,OUT_J,SURF,CMARK,DEM,RUNOFF,SDEP,SDEN,DEST_I,DEST_J,XIND,
     &YIND,PATH_TOTAL,SX)
                              C11=CATCH_FLAG(DEST_I,DEST_J)

                              IF ((C11.EQ.0).AND.
     &(PATH_TOTAL.GE.100)) THEN
                              NUM11=COUNT(XIND.NE.0)
                              NUM12=ABS(PP-OUT_I)
                              NUM13=ABS(QQ-OUT_J)

                              ! SIMULATE ONLY OVERFLOW IF THE
                              ! DESTINATION IS IN THE IMMEDIATE VICINITY
                              ! OF THE OUTLET CELL OR IF THE OUTLET IS
                              ! IN THE IMMEDIATE VICINITY OF THE LAKE
                              ! NUCLEUS

                              IF
     &((NUM11.GT.2).AND.((NUM12.GT.1).OR.(NUM13.GT.1))) THEN
                                      CALL CHANNEL_INC1(DRAIN_INCISE,
     &OUT_I,OUT_J,DEST_I,DEST_J,RUNOFF,LAKE_HT,LAKE_AR,PP,QQ,LAKE_BASE,
     &SURF,DEM,PATH_TOTAL,MARK,CHN_DEC,SUMINC,RUN_X,RUN_Y,RUN_LAK,XIND
     &,YIND,LAKE_RED,K1,K2,K3,K4,CMARK,LAKE2RUN,ROWS,COLS,SX)

                              ELSE IF 
     &((NUM11.EQ.2).OR.((NUM12.LE.1).AND.(NUM13.LE.1))) THEN
                                      CALL ONLY_OVERFLOW1(SURF,DEM,RUN_Y
     &,RUN_X,RUN_LAK,OUT_I,OUT_J,DEST_I,DEST_J,CMARK,LAK_NO_INC,MARK,
     &RUNOFF,CHN_DEC,XIND,YIND,ROWS,COLS,SX,PP,QQ,K1,K2,K3,K4)

                                      FLAG_OV(PP,QQ)=1
                              ELSE

                              END IF
                              END IF

                              ! IF THE OUTLET CELL IS CREVASSED THEN ALL
                              ! RUNOFF FROM THE LAKE GOES INTO THE
                              ! CREVASSE

                              IF ((C11.EQ.1).AND.
     &(PATH_TOTAL.LE.0).AND.(CMARK(DEST_I,DEST_J).EQ.1)) THEN

                              CALL ONLY_OVERFLOW1(SURF,DEM,RUN_Y
     &,RUN_X,RUN_LAK,OUT_I,OUT_J,DEST_I,DEST_J,CMARK,LAK_NO_INC,MARK,
     &RUNOFF,CHN_DEC,XIND,YIND,ROWS,COLS,SX,PP,QQ,K1,K2,K3,K4)

                              FLAG_OV(PP,QQ)=1

                              END IF

                      END IF


              END IF
      END IF

100   CONTINUE
      RETURN

      END SUBROUTINE LAKE_CHN_INC_OV1
