      program overlap_test

      parameter (n=10)

      real a(n, n, n, n)
      call cmf_random (a)
      call test_leftup1 (a,n)
      call test_rightdown2 (a,n)
      end

      subroutine test_leftup1 (a, n)

      integer n

      real a(n,n,n,n), b(n[1:0],n[1:0],n[1:0],n[1:0])
      real a1(n,n,n,n)
      logical equal (n,n,n,n)
      integer errors

c     call print_a (a, n)

      b = a
      forall (i=1:n,j=1:n,k=1:n,l=1:n)
         a1 (l,k,j,i) = b (l-1,k-1,j-1,i-1)
      end forall
c     call print_a (a1, n)


      a = cshift (a, 1, -1)
      a = cshift (a, 2, -1)
      a = cshift (a, 3, -1)
      a = cshift (a, 4, -1)
c     call print_a (a, n)

      equal = (a1 .eq. a)
      errors = count (equal)
      errors = n*n*n*n - errors

      print *, errors, ' Errors for left overlapping'
      end

      subroutine test_rightdown2 (a, n)

      integer n

      real a(n,n,n,n), b(n[0:2],n[0:3],n[0:1],n[0:2])   
      real a1(n,n,n,n)
      logical equal (n,n,n,n)
      integer errors

c     call print_a (a, n)

      b = a
      forall (i=1:n,j=1:n,k=1:n,l=1:n)
         a1 (j,i,k,l) = b (j+2,i+3,k+1,l+2)
      end forall
c     call print_a (a1, n)

      a = cshift (a, 1, 2)
      a = cshift (a, 2, 3)
      a = cshift (a, 3, 1)
      a = cshift (a, 4, 2)
c     call print_a (a, n)

      equal = (a1 .eq. a)
      errors = count (equal)
      errors = n*n*n*n - errors

      print *, errors, ' Errors for right overlapping'
      end

      subroutine print_a (a, n)
      real a(n,n,n,n)
      integer i, j, k, l, n
      do i = 1, n
       do j = 1, n
         do k = 1, n
           do l = 1, n
            print *, 'a(',i,',',j,',',k,',',l,') = ', a(i,j,k,l)
           end do
         end do
       end do
      end do
      end

