      SUBROUTINE 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)

      ! THIS SUBROUTINE DELINEATES THE FLOW PATH FROM THE OUTKET CELL TO
      ! AN APPROPRIATE DESTINATION CELL

      ! DESCRIPTION OF THE VARIABLES:

      ! RUNOFF: CONTAINS RUNOFF MELTWATER (IN METERS) FOR EVERY GRID
      ! CELL. 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

      ! XIND,YIND: CONTAINS THE COORDINATES OF THE PIXELS LYING ALONG
      ! THE SUPRGLACIAL MELTWATER PATH. GETS MODIFIED 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

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

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

      ! DEST_I,DEST_J: STORES COORDINATES OF THE DESTINATION OF THE
      ! MELTWATER PATH. GETS UNMODIFIED IN THIS SUBROUTINE

      ! PATH_TOTAL: STORES TOTAL PATH LENGTH OF THE SUPRAGLACIAL
      ! MELTWATER CHANNEL. GETS MODIFIED IN THIS SUBROUTINE

      ! SX: CONSTANT

      ! 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

      IMPLICIT NONE

      INTEGER :: SX,OUT_I,OUT_J,ROWS,COLS,DEST_I,DEST_J,CMARK(COLS,ROWS)
     &,NN,COUNTYY,COUNTXX,COUNTZZ,XIND(SX),YIND(SX),S,K,TIMESTEP,
     &II(9),JJ(9),N,A,B,XX,YY,XX1,YY1,NUMX,I1,ICLOW

      DOUBLE PRECISION :: MU,SURF(COLS,ROWS),PATHY(SX),DEL_T(SX),
     &PATH_TOTAL,DEM(COLS,ROWS),RUNOFF(COLS,ROWS),SDEP(COLS,ROWS),
     &SDEN(COLS,ROWS),VALS(9),LOW,LAKE_DEPTH(COLS,ROWS),SLOPE,KK,V,SUM1
     &,MELT(COLS,ROWS),RAIN(COLS,ROWS),Q,T_CB

      TIMESTEP=86400

      LAKE_DEPTH=SURF-DEM

      S=OUT_I
      K=OUT_J
      COUNTXX=1
      COUNTYY=1
      COUNTZZ=1
      NN=1
      MU=1.763e-3

      ! ESTIMATING THE LENGTH,SLOPE AND LOCATION OF THE FLOWPATH FOR
      ! THE OVERFLOWING LAKE

      IF ((CMARK(S,K).EQ.0).OR.(LAKE_DEPTH(S,K).EQ.0)) THEN

      DO WHILE ((NN.EQ.1).AND.(S.GE.2).AND.(K.GE.2).AND.(S.LE.COLS-1)
     &.AND.(K.LE.ROWS-1).AND.(CMARK(S,K).EQ.0).AND.(SURF(S,K).GT.0))

      IF (COUNTZZ.EQ.1) THEN
              XIND(COUNTXX)=S
              YIND(COUNTXX)=K
              COUNTXX=COUNTXX+1
              COUNTZZ=0
      END IF
      II=(/S-1,S-1,S-1,S,S,S,S+1,S+1,S+1/)
      JJ=(/K-1,K,K+1,K-1,K,K+1,K-1,K,K+1/)

      DO 120 N=1,9
      A=II(N)
      B=JJ(N)
      VALS(N)=SURF(A,B)
120   CONTINUE
      ICLOW=0
      LOW=999999

      DO 130 N=1,9
      IF (VALS(N).LT.LOW) THEN
              ICLOW=N
              LOW=VALS(N)
      END IF
130   CONTINUE

      IF (VALS(5).EQ.LOW) THEN
              NN=0
              PATHY(COUNTYY)=0
              COUNTYY=COUNTYY+1
      ELSE
              IF (((ABS(II(ICLOW)-S)).EQ.1).AND.((ABS(JJ(ICLOW)-
     &K)).EQ.1)) THEN
                      PATHY(COUNTYY)=100*1.414
              ELSE
                      PATHY(COUNTYY)=100
              END IF

              S=II(ICLOW)
              K=JJ(ICLOW)
              XIND(COUNTXX)=S
              YIND(COUNTXX)=K
              COUNTXX=COUNTXX+1
              COUNTYY=COUNTYY+1
              NN=1
      END IF
      END DO

      ELSE
      PATHY(1)=0
      XIND(1)=S
      YIND(1)=K
      END IF

      ! ESTIMATING THE SLOPE, DESTINATION IN THE PATH

      NUMX=COUNT(XIND.NE.0)

      IF (NUMX.GT.1) THEN
              NUMX=COUNT(XIND.NE.0)
              DO 140 I1=1,NUMX-1
              XX=XIND(I1)
              YY=YIND(I1)
              XX1=XIND(I1+1)
              YY1=YIND(I1+1)
              SLOPE=(SURF(XX,YY)-SURF(XX1,YY1))/PATHY(I1)
              KK=0.077*(0.001*0.001)*EXP(-7.8*(SDEN(XX,YY)/1000))

              IF (SLOPE.LT.0) SLOPE=0

              IF (SDEP(XX,YY).GE.0.25) THEN
                      Q=(RUNOFF(XX,YY))*100*100
                     IF (I1.EQ.1) THEN
                             T_CB=(0.63*SDEP(XX,YY))/
     &(((3*1000*9.8/MU)**(1/3))*(KK**(1/3))*(Q**(2/3)))
                     ELSE
                             T_CB=0.0
                     END IF
                     V=((1000*9.8/MU)*KK*SLOPE)/0.68
              ELSE
                      T_CB=0.0
                      IF (RUNOFF(XX,YY).LE.0.034) THEN
                              V=(1/0.05)*(0.034**(2/3))*SQRT(SLOPE)
                      ELSE
                              V=(1/0.05)*(RUNOFF(XX,YY)**(2/3))
     &*SQRT(SLOPE)
                      END IF
              END IF
              DEL_T(I1)=(PATHY(I1)/V)+T_CB
              IF (V.LE.0) DEL_T(I1)=9999999
140           CONTINUE

              XX=XIND(1)
              YY=YIND(1)
              XX1=XIND(NUMX)
              YY1=YIND(NUMX)
              COUNTXX=0
              SUM1=0
              DEL_T=DEL_T/86400.

              ! DESTINATION IS LOCATED WHERE THE TOTAL DELAY TIME IS ONE
              ! TIMESTEP OR 1 DAY

              IF (SUM(DEL_T).LT.1) THEN
                      DEST_I=XX1 ! COL NO. OF DESTINATION
                      DEST_J=YY1 ! ROW NO. OF DESTINATION
                      PATH_TOTAL=SUM(PATHY) ! TOTAL PATH LENGTH

              ELSE
                      DO WHILE ((SUM1.LE.1).AND.(COUNTXX.LT.NUMX))
                      COUNTXX=COUNTXX+1
                      SUM1=SUM1+DEL_T(COUNTXX)
                      END DO
                      DEST_I=XIND(COUNTXX) ! COL NO. OF DESTINATION
                      DEST_J=YIND(COUNTXX) ! ROW NO. OF DESTINATION
                      PATH_TOTAL=(SUM(PATHY(1:COUNTXX))) ! TOTAL PATH LENGTH

              END IF
      ELSE
              PATH_TOTAL=0
              DEST_I=OUT_I
              DEST_J=OUT_J

      END IF

      RETURN
      END SUBROUTINE PATH_SEL_CHN_INC1
