       program scatter
c
#include "mpi.fort.h"
c
       integer i,ndata,indirection, BUFSIZE, global_size, BLOCK
       integer my_index(4)
       parameter(BUFSIZE = 4)
       integer iglobal_ref(4),ilocal_ref(4)
       double precision x(4),y(4+BUFSIZE)
       integer itabptr, ischedptr, build_translation_table
       real buffer(3), aloc(4)


       BLOCK = 1
       global_size = 8
       if (MPI_numnodes() .le. global_size)  then
          my_size = global_size/MPI_numnodes()
       else
          if (MPI_mynode() .lt. global_size) then
             my_size = 1
          else
             my_size = 0
          endif
       endif
       if(MPI_mynode() .eq. 0) then
         iglobal_ref(1) = 4
         iglobal_ref(2) = 8
         iglobal_ref(3) = 2
         ndata = 3
       else if ( MPI_mynode() .eq. 1) then
         iglobal_ref(1) = 5
         iglobal_ref(2) = 3
         iglobal_ref(3) = 4
         iglobal_ref(4) = 1
         ndata = 4
        else
         ndata  = 0
        end if


C initialize CHAOS environment
        call PARTI_setup()
c the following is the inspector code
         call reglocalize(BLOCK,global_size,ischedptr,iglobal_ref,
     $                  ilocal_ref,ndata,n_off_proc,my_size,1)

          do 11 i=1,my_size
            aloc(i) = 0.0
11        continue

        if(MPI_mynode().eq.0) then
            aloc(ilocal_ref(1)) = 10.01
            aloc(ilocal_ref(2)) = 10.01
            aloc(ilocal_ref(3)) = 10.01
        endif

        if(MPI_mynode().eq.1) then
            aloc(ilocal_ref(1)) = 100.10
            aloc(ilocal_ref(2)) = 100.10
            aloc(ilocal_ref(3)) = 100.10
            aloc(ilocal_ref(4)) = 100.10
        endif

        call fscatter(aloc(my_size+1),aloc,ischedptr)

        if (my_size .gt. 0)  then
        write(*,*) 'Proc',MPI_mynode(),':',(aloc(i),i=1,my_size)
        end if
        end
