!2345678901234567890123456789012345678901234567890123456789012345678901234567890
!    &                                                                  &

      SUBROUTINE globalInit(numChunk)
          IMPLICIT NONE
          INTEGER numChunk
          numChunk = 5
      END SUBROUTINE

      SUBROUTINE processorInit()
      END SUBROUTINE

      INTEGER FUNCTION chunkInit(width,height)
          USE chunkModule
	  IMPLICIT NONE

          INTEGER width, height
          TYPE(chunk_type), POINTER :: chunk
          INTEGER i,j
          	
          chunk => allocateChunk(chunkInit)

          chunk%height = height
          chunk%width = width + 2

          DO i = 1, width
            DO j = 0, height-1
              chunk%temperature(j+1, i+1) = 100*(i-1) + j
            ENDDO 
          ENDDO
        END FUNCTION        

 	SUBROUTINE fillBorder(index, d, toleft)
          USE chunkModule
	  IMPLICIT NONE

          INTEGER index
          REAL(KIND=8) d(1:*)
          INTEGER toleft
          TYPE(chunk_type), POINTER :: chunk
          INTEGER w,i

          chunk => getChunk(index)
          IF (toleft .eq. 1) THEN
             w = 2
          ELSE
             w = chunk%width-1
          END IF

          DO i = 1 , chunk%height
              d(i) = chunk%temperature(i, w);
          END DO
        END SUBROUTINE

        SUBROUTINE nextIteration(index)
          USE chunkModule
	  IMPLICIT NONE

          INTEGER index
          TYPE(chunk_type), POINTER :: chunk
          INTEGER i,j

          chunk => getChunk(index)
          DO i = 2, 11
           DO j = 2, 99
             chunk%temperature(j,i) = ( chunk%temperature(j, i) + chunk%&
     &temperature(j, i+1) + chunk%temperature(j, i-1) + chunk%temperatur&
     &e(j+1, i) + chunk%temperature(j-1, i))/5.0
	   END DO
	  ENDDO
        END SUBROUTINE

 	SUBROUTINE copyBorder(index,a, fromleft)
          USE chunkModule
	  IMPLICIT NONE

          INTEGER index
          REAL(KIND=8) a(*)
          INTEGER fromleft
          TYPE(chunk_type), POINTER :: chunk
          INTEGER w, i

          chunk => getChunk(index)
          IF (fromleft .eq. 1) THEN
            w = 1
          ELSE
            w = chunk%width
          END IF

          DO i = 1 , chunk%height
              chunk%temperature(i, w) = a(i)
          END DO
        END SUBROUTINE


!2345678901234567890123456789012345678901234567890123456789012345678901234567890
!    &                                                                  &
