      SUBROUTINE LAKE_NUCLEUS_ISOLATION21(SURF,DEM,NUC_I,NUC_J,ROWS,COLS
     &,SX)

      ! THIS SUBROUTINE SEPARATED THE LAKE NUCLEI. THESE LAKES MIGHT
      ! DRAIN VIA HYDROFRACTURE OR CHANEL INCISION

      ! DESCRIPTION OF VARIABLES:

      ! 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

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

      ! SX: CONSTANT

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

      IMPLICIT NONE

      INTEGER :: I,J,ROWS,COLS,NUC_I(SX),NUC_J(SX),MARKY(COLS,ROWS),
     &MARKY1(COLS,ROWS),K1,K2,K3,K4,COUNTY,LAKE_NUCLEUS(COLS,ROWS),
     &PP,QQ,SX,MARK2(COLS,ROWS)
      DOUBLE PRECISION :: SURF(COLS,ROWS),DEM(COLS,ROWS),VALS(9),
     &LAKE_DEPTH(COLS,ROWS),SURFY_LAK,RUNOFF(COLS,ROWS)

      LAKE_DEPTH=SURF-DEM ! LAKE DEPTH MATRIX
      K1=0
      K2=0
      K3=0
      K4=0
      LAKE_NUCLEUS=0.

      DO 100 I=2,COLS-1
      DO 110 J=2,ROWS-1

      PP=I
      QQ=J

      ! IF LAKE DEPTH IS POSITIVE AND HAS NOT BEEN ENCOUNTERED IN THE
      ! TIMESTEP BEFORE

      IF ((LAKE_DEPTH(I,J).GT.0).AND.(MARKY1(I,J).EQ.0)) THEN

              ! CALL THE LAKE DELINEATION ALGORITHM TO GET THE LAKE NUCLEUS

              CALL LAKE_DEL1(PP,QQ,MARKY,MARKY1,SURF,DEM,K1,K2,K3,K4,
     &COLS,ROWS)
              K1=0
              K2=0
              K3=0
              K4=0

              ! IF LEGITIMATE NUCLEUS AND THERE IS NON-ZERO RUNOFF IN
              ! THE LAKE

              IF ((PP.GT.0).AND.(QQ.GT.0)) THEN
                      LAKE_NUCLEUS(PP,QQ)=1
              END IF
              MARKY=0.
      END IF

110   CONTINUE
100   CONTINUE

      COUNTY=1
      DO 120 I=2,COLS-1
      DO 130 J=2,ROWS-1
      IF ((LAKE_NUCLEUS(I,J).EQ.1)) THEN
              NUC_I(COUNTY)=I
              NUC_J(COUNTY)=J
              COUNTY=COUNTY+1
      END IF
130   CONTINUE
120   CONTINUE

      RETURN

      END SUBROUTINE LAKE_NUCLEUS_ISOLATION21

