       program local
c
#include "mpi.fort.h"
c
       integer i,ndata,indirection, BUFSIZE
       parameter(BUFSIZE = 4)
       integer my_index(5),global_ref(5),local_ref(5)
       double precision x(5),y(5+BUFSIZE)
       integer tabptr,schedptr, build_translation_table
c data initialization
       if(MPI_mynode() .eq. 0) then
         my_index(1) = 2
         my_index(2) = 3
         my_index(3) = 6
         my_size = 3
         global_ref(1) = 4
         global_ref(2) = 8
         global_ref(3) = 2
         ndata = 3
       else if(MPI_mynode() .eq. 1) then
         my_index(1) = 1
         my_index(2) = 4
         my_index(3) = 5
         my_index(4) = 7
         my_index(5) = 8
         my_size = 5
         global_ref(1) = 5
         global_ref(2) = 3
         global_ref(3) = 4
         global_ref(4) = 1
         global_ref(5) = 7
         ndata = 5
        else 
         my_size = 0
         ndata = 0
        end if
        do 20 i=1,my_size
           x(i) = my_index(i)
           y(i) = 2*my_index(i)
20       continue
C initialize Chaos environment
        call PARTI_setup()
c the following is the inspector code
         tabptr = build_translation_table(1,my_index,my_size)
         call localize(tabptr,schedptr,global_ref,
     $        local_ref,ndata,n_off_proc,my_size,1)
c
         do 10 i=1,ndata
           global_ref(i) = local_ref(i)
10       continue
c  end of the inspector and the executor begins
         call dgather(y(my_size+1),y,schedptr)
         do 30 i=1,ndata
           indirection = global_ref(i)
           x(i) = x(i) + y(indirection)
30       continue
c end of the executor code
         if (MPI_mynode() .eq. 0) then
         WRITE(*,*) (X(I), I=1,my_size)
         WRITE(*,*) (global_ref(I), I=1,ndata)
         WRITE(*,*) (Y(global_ref(I)), I=1,ndata)
         end if
         call MPI_gsync()
         if (MPI_mynode() .eq. 1) then
         WRITE(*,*) (X(I), I=1,MY_SIZE)
         WRITE(*,*) (global_ref(I), I=1,ndata)
         WRITE(*,*) (Y(global_ref(I)), I=1,ndata)
         end if
         
         end
