      program main
      use types
      use parameters
      real(SP), dimension(NX,NY,NZ)::child
      real(SP), dimension(NX)    :: xx
      real(SP), dimension(NY)    :: yy
      real(SP), dimension(NZ)    :: zz
      integer(I4B)              :: order, dim, refinerat
      real t1(PX*PY), t2(PX*PY)

!HPF$ PROCESSORS P(PX,PY)
!HPF$ DISTRIBUTE (BLOCK,BLOCK,*) onto P :: child
!HPF$ ALIGN xx(:) with child(:,*,*)
!HPF$ ALIGN yy(:) with child(*,:,*)
!HPF$ ALIGN zz(:) with child(*,*,:)
!HPF$ DISTRIBUTE t1(BLOCK)
!HPF$ DISTRIBUTE t2(BLOCK)

      INTERFACE
      subroutine interpolate(childgrid,order,dim,refinerat,xx,yy,zz)
      use parameters
      use types
      implicit none
      real(SP), dimension(:,:,:) :: childgrid
      integer(I4B)               :: order, dim, refinerat
      real(SP), dimension(:)     :: xx,yy,zz 
!HPF$ PROCESSORS P(PX,PY)
!HPF$ DISTRIBUTE *(BLOCK,BLOCK,*) onto *P :: childgrid
!HPF$ ALIGN xx(:) with *childgrid(:,*,*)
!HPF$ ALIGN yy(:) with *childgrid(*,:,*)
!HPF$ ALIGN zz(:) with *childgrid(*,*,:)
      end subroutine interpolate

      extrinsic(hpf_local) subroutine timer(return_time, initial_time)
      real, dimension(:), intent(in)  :: initial_time
      real, dimension(:), intent(out) :: return_time
!HPF$ DISTRIBUTE *(block) :: initial_time
!HPF$ ALIGN return_time with initial_time
      end subroutine timer

      END INTERFACE

      
      call timer(t2,t1)
      forall(i=1:NX) xx(i)=i
      forall(i=1:NY) yy(i)=i
      forall(i=1:NZ) zz(i)=i

      order = 2
      dim = 3
      refinerat = 2
         
c      do k=1,13
c       do i=1,13
c        do j=1,13,3
c      child(i,j,k) = xx(i)*xx(i)*yy(j)*zz(k)
c         enddo
c        enddo
c      enddo

      forall(i=1:NX,j=1:NY:3,k=1:NZ) child(i,j,k)=
     &                            xx(i)*xx(i)*yy(j)*zz(k)
       

!      do k=1,100
!       do j=1,100
!        do i=1,100    
!      write(6,*) zz(11),yy(13),xx(12),child(12,13,11)
!        enddo
!       enddo
!      enddo
      
      write(6,*) 'calling interpolate'

      call interpolate(child,order,dim,refinerat,xx,yy,zz)

      call timer(t1,t2)
      print *,'time',t1,' seconds'
  
c      do k=1,13
c       do j=1,13
c        do i=1,13    
c          write(6,*) zz(k),yy(j),xx(i),child(i,j,k)
c        enddo
c       enddo
c      enddo
 
      end program
      

      extrinsic(hpf_local) subroutine timer(return_time, initial_time)
      real, dimension(:), intent(in)  :: initial_time
      real, dimension(:), intent(out) :: return_time

      return_time(lbound(return_time, 1)) =     
     &        secnds(initial_time(lbound(initial_time, 1)))

      end






