      program replicate

      real a(10,10,10,10)
      real ra(5,5,5,10), x
      integer i, j, k, l, n

cmf$  layout ra(:replicated)

      forall (i=1:10,j=1:10,k=1:10,l=1:10)
        a(i,j,k,l) = i + 2*j - k + 3*l
      end forall

      ra = 0
      ra = a(4:8,2:6,5:9,1:10)

      n = 0
      do i = 4, 8
        do j = 2, 6
          do k = 5,9
            do l = 1, 10
               n = n + i + 2*j - k + 3*l
            end do
          end do
        end do
      end do

      x = sum (ra)
      print *, 'Result is ', x, ' should be ', n

      end
