      SUBROUTINE MARGIN_FLOW1(RUNOFF,COLS,ROWS,ICE,DEM)

      ! THIS SUBROUTINE REMOVES THE WATER AT THE EDGES OF THE STUDY AREA
      ! AND TRANSFERS THAT WATER TO THE SEA OR LAND. THIS REPRESENTS THE
      ! PHENOMENON WHERE THE MELTWATER RUOFF FROM THE ICE SHEET FLOWS
      ! OFF THE ICE SHEET ONTO THE LAND OR NON-ICE AREA

      ! DESCRIPTION OF VARIABLES:

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

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

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

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

      IMPLICIT NONE

      INTEGER :: COLS,ROWS,I,J,NTHREADS,OMP_GET_MAX_THREADS,
     &OMP_GET_THREAD_NUM,CHUNK,ISTART,IEND,TID 

      DOUBLE PRECISION :: RUNOFF(COLS,ROWS),ICE(COLS,ROWS),
     &DEM(COLS,ROWS) 

      ISTART=1
      IEND=COLS

!$OMP PARALLEL
!$OMP& DEFAULT(SHARED)
!$OMP& PRIVATE(ISTART,IEND,TID,CHUNK,I,J)
!$    NTHREADS=OMP_GET_MAX_THREADS()
!$    TID=OMP_GET_THREAD_NUM()
!$    CHUNK=(COLS+NTHREADS-1)/NTHREADS
!$    ISTART=TID*CHUNK+1
!$    IEND=MIN((TID+1)*CHUNK,COLS)      
      DO 100 I=ISTART,IEND
      DO 200 J=1,ROWS
              IF (ICE(I,J).LE.1) THEN
!$OMP CRITICAL                      
                      RUNOFF(I,J)=0
                     
!$OMP END CRITICAL                      
              END IF
              IF (DEM(I,J).EQ.0) THEN
!$OMP CRITICAL                      
                      RUNOFF(I,J)=0
!$OMP END CRITICAL                      
              END IF
200   CONTINUE
100   CONTINUE
!$OMP END PARALLEL
      RETURN

      END SUBROUTINE MARGIN_FLOW1
