      program MAIN
      real  X(100),Y(100),t1(100),t2(100),t3(400),t4(400)
      real  u1,v1,u2,v2
      integer  pDim(1),comm,xDAD,yDAD,t1DAD,t2DAD
      integer  i,ll,lu,ls,amount1,amount2,status1,status2
!HPF$      PROCESSORS P(4)
!HPF$      TEMPLATE TX(400),TY(-200:199)
!HPF$      DISTRIBUTE TX  (block) onto  P
!HPF$      DISTRIBUTE TY  (block) onto  P
!HPF$      ALIGN X (i) with TX(2 * i+1)
!HPF$      ALIGN Y (i) with TY((3 * i) - 50)
      pDim(1) = 4
      call MPI_INIT (ierror)
      call gridInit (1, pDim, comm)
      xDAD = setPerArrayInfo(X,2,4,1,comm,1)
      call setCommonValues (xDAD, 1, 2, 99, 1, 0, 1, 400, 1, 2, 1, 4)
      call setDiffValues (xDAD, 1)
      yDAD = setPerArrayInfo(Y,2,4,1,comm,1)
      call setCommonValues (yDAD, 1, 1, 100, 1, 0, -200, 199, -50, 3, 1, 4)
      call setDiffValues (yDAD, 1)
      call loopBounds (xDAD, 2, 99, 1, ll, lu, ls)
      X(i) = 0
      call loopBounds (yDAD, 1, 100, 1, ll, lu, ls)
      Y(i) = localToGlobal(yDAD,i,1)
      call loopBounds (xDAD, 2, 99, 1, ll, lu, ls)
      amount1 = detectCommunication(xDAD,yDAD,1,2,99,1,1,1,u1,v1,status1)
      if (status1 .eq. 1) then
          t1DAD = setPerArrayInfo(t1,2,4,1,comm,1)
         call setCommonValues (t1DAD, 1, 1, 100, 1, 0, -200, 199, -50, 3, 1, 4)
         call setDiffValues (t1DAD, 1)
         call tshift (yDAD, t1DAD, amount1)
        else if (status1 .eq. 2) then
            call concatenate (yDAD, t3)
      endif
      amount2 = detectCommunication(xDAD,yDAD,1,2,99,1,1,-1,u2,v2,status2)
      if (status2 .eq. 1) then
          t2DAD = setPerArrayInfo(t2,2,4,1,comm,1)
         call setCommonValues (t2DAD, 1, 1, 100, 1, 0, -200, 199, -50, 3, 1, 4)
         call setDiffValues (t2DAD, 1)
         call tshift (yDAD, t2DAD, amount2)
        else if (status2 .eq. 2) then
            call concatenate (yDAD, t4)
      endif
      i1 = NINT (u1 * i+v1)
      i2 = NINT (u2 * i+v2)
      if ((status1 .eq. 0) .and. (status2 .eq. 0)) then
          X(i) = Y(i1)+Y(i2)
      else if ((status1 .eq. 0) .and. (status2 .eq. 1)) then
          X(i) = Y(i1)+t2(i2)
      else if ((status1 .eq. 0) .and. (status2 .eq. 2)) then
          X(i) = Y(i1)+t4(i2)
      else if ((status1 .eq. 1) .and. (status2 .eq. 0)) then
          X(i) = t1(i1)+Y(i2)
      else if ((status1 .eq. 1) .and. (status2 .eq. 1)) then
          X(i) = t1(i1)+t2(i2)
      else if ((status1 .eq. 1) .and. (status2 .eq. 2)) then
          X(i) = t1(i1)+t4(i2)
      else if ((status1 .eq. 2) .and. (status2 .eq. 0)) then
          X(i) = t3(i1)+Y(i2)
      else if ((status1 .eq. 2) .and. (status2 .eq. 1)) then
          X(i) = t3(i1)+t2(i2)
      else if ((status1 .eq. 2) .and. (status2 .eq. 2)) then
          X(i) = t3(i1)+t4(i2)
      else
          print *, 'something is wrong !'
      endif
      call DAD_inherit (xDAD, xsDAD, 1, 2, 98, 2)
      call DAD_inherit (yDAD, ysDAD, 1, 1, 99, 2)
      call FOO (X, xsDAD, Y, ysDAD)
      call DAD_inherit (xDAD, xsDAD, 1, 3, 98, 2)
      call DAD_inherit (yDAD, ysDAD, 1, 1, 99, 2)
      call FOO (X, xsDAD, Y, ysDAD)
      print *
      end


