

























































































































 


































































































































































 






















































































































































































 






















































 










 








































































































































































































































 










                                
                                

                                
                                

                                
                                

                                





































module pointwise

  implicit none
  private
  public calc_position
  public calc_offsets
  public get_scalar
  public get_vector
  public get_tensor
  public get_connections
  public set_scalar
  public set_vector
  public set_tensor
  public set_connections
  public get_scalarderivs
  public get_vectorderivs
  public get_tensorderivs
  public get_scalarderivs2
  public get_vectorderivs2
  public get_tensorderivs2
  public get_scalarderivs3
  public get_vectorderivs3
  public get_tensorderivs3
contains




  subroutine get_derivs (a, f, pos, off, dx, order)
    REAL*8, intent(in)            :: a(*)
    REAL*8, intent(out)           :: f(3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    integer :: order1
    integer :: i
    order1 = 2
    if (present(order)) order1 = order
    select case (order1)
    case (2)
       do i=1,3
          f(i) = (a(pos+off(i)) - a(pos-off(i))) / (2*dx(i))
       end do
    case (4)
       do i=1,3
          f(i) = (- a(pos+2*off(i)) + 8*a(pos+off(i)) - 8*a(pos-off(i)) + a(pos-2*off(i))) / (12*dx(i))
       end do
    case default
       call CCTK_Warn(0,36,"pointwise.F90","TGRtensor", "Unsupported finite differencing order")
    end select
  end subroutine get_derivs
  subroutine get_derivs2 (a, f, pos, off, dx, order)
    REAL*8, intent(in)            :: a(*)
    REAL*8, intent(out)           :: f(3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    integer :: order1
    integer :: i
    order1 = 2
    if (present(order)) order1 = order
    select case (order1)
    case (2)
       do i=1,3
          f(i,i) = (a(pos+off(i)) - 2*a(pos) + a(pos-off(i))) / dx(i)**2
       end do
       f(1,2) = (  a(pos-off(1)-off(2)) - a(pos+off(1)-off(2)) &
            &    - a(pos-off(1)+off(2)) + a(pos+off(1)+off(2))) / (4*dx(1)*dx(2))
       f(2,1) = f(1,2)
       f(1,3) = (  a(pos-off(1)-off(3)) - a(pos+off(1)-off(3)) &
            &    - a(pos-off(1)+off(3)) + a(pos+off(1)+off(3))) / (4*dx(1)*dx(3))
       f(3,1) = f(1,3)
       f(2,3) = (  a(pos-off(2)-off(3)) - a(pos+off(2)-off(3)) &
            &    - a(pos-off(2)+off(3)) + a(pos+off(2)+off(3))) / (4*dx(2)*dx(3))
       f(3,2) = f(2,3)
    case (4)
       do i=1,3
          f(i,i) = (- a(pos-2*off(i)) + 16*a(pos-off(i)) - 30*a(pos) + 16*a(pos+off(i)) - a(pos+2*off(i))) / (12*dx(i)**2)
       end do
       f(1,2) = (    a(pos+2*off(1)+2*off(2)) -  8*a(pos+off(1)+2*off(2)) +  8*a(pos-off(1)+2*off(2)) -   a(pos-2*off(1)+2*off(2)) &
            &    - 8*a(pos+2*off(1)+  off(2)) + 64*a(pos+off(1)+  off(2)) - 64*a(pos-off(1)+  off(2)) + 8*a(pos-2*off(1)+  off(2)) &
            &    + 8*a(pos+2*off(1)-  off(2)) - 64*a(pos+off(1)-  off(2)) + 64*a(pos-off(1)-  off(2)) - 8*a(pos-2*off(1)-  off(2)) &
            &    -   a(pos+2*off(1)-2*off(2)) +  8*a(pos+off(1)-2*off(2)) -  8*a(pos-off(1)-2*off(2)) +   a(pos-2*off(1)-2*off(2)))&
  & / (144*dx(1)*dx(2))
       f(2,1) = f(1,2)
       f(1,3) = (    a(pos+2*off(1)+2*off(3)) -  8*a(pos+off(1)+2*off(3)) +  8*a(pos-off(1)+2*off(3)) -   a(pos-2*off(1)+2*off(3)) &
            &    - 8*a(pos+2*off(1)+  off(3)) + 64*a(pos+off(1)+  off(3)) - 64*a(pos-off(1)+  off(3)) + 8*a(pos-2*off(1)+  off(3)) &
            &    + 8*a(pos+2*off(1)-  off(3)) - 64*a(pos+off(1)-  off(3)) + 64*a(pos-off(1)-  off(3)) - 8*a(pos-2*off(1)-  off(3)) &
            &    -   a(pos+2*off(1)-2*off(3)) +  8*a(pos+off(1)-2*off(3)) -  8*a(pos-off(1)-2*off(3)) +   a(pos-2*off(1)-2*off(3)))&
  & / (144*dx(1)*dx(3))
       f(3,1) = f(1,3)
       f(2,3) = (    a(pos+2*off(2)+2*off(3)) -  8*a(pos+off(2)+2*off(3)) +  8*a(pos-off(2)+2*off(3)) -   a(pos-2*off(2)+2*off(3)) &
            &    - 8*a(pos+2*off(2)+  off(3)) + 64*a(pos+off(2)+  off(3)) - 64*a(pos-off(2)+  off(3)) + 8*a(pos-2*off(2)+  off(3)) &
            &    + 8*a(pos+2*off(2)-  off(3)) - 64*a(pos+off(2)-  off(3)) + 64*a(pos-off(2)-  off(3)) - 8*a(pos-2*off(2)-  off(3)) &
            &    -   a(pos+2*off(2)-2*off(3)) +  8*a(pos+off(2)-2*off(3)) -  8*a(pos-off(2)-2*off(3)) +   a(pos-2*off(2)-2*off(3)))&
  & / (144*dx(2)*dx(3))
       f(3,2) = f(2,3)
    case default
       call CCTK_Warn(0,83,"pointwise.F90","TGRtensor", "Unsupported finite differencing order")
    end select
  end subroutine get_derivs2
  subroutine get_derivs3 (a, f, pos, off, dx, order)
    REAL*8, intent(in)            :: a(*)
    REAL*8, intent(out)           :: f(3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    integer :: order1
    order1 = 2
    if (present(order)) order1 = order
    select case (order1)
    case (2)
       f(1,1,1) = (a(pos+2*off(1)) - 2*a(pos+off(1)) + 2*a(pos-off(1)) - a(pos-2*off(1))) / (2*dx(1)**3)
       f(2,1,1) = (a(pos+off(1)+off(2)) - 2*a(pos+off(2)) + a(pos-off(1)+off(2)) - a(pos+off(1)-off(2)) + 2*a(pos-off(2)) - a(pos-o&
  &ff(1)-off(2))) / (2*dx(1)*dx(1)*dx(2))
       f(3,1,1) = (a(pos+off(1)+off(3)) - 2*a(pos+off(3)) + a(pos-off(1)+off(3)) - a(pos+off(1)-off(3)) + 2*a(pos-off(3)) - a(pos-o&
  &ff(1)-off(3))) / (2*dx(1)*dx(1)*dx(3))
       f(1,2,1) = f(2,1,1)
       f(2,2,1) = (a(pos+off(1)+off(2)) - 2*a(pos+off(1)) + a(pos+off(1)-off(2)) - a(pos-off(1)+off(2)) + 2*a(pos-off(1)) - a(pos-o&
  &ff(1)-off(2))) / (2*dx(1)*dx(2)*dx(2))
       f(3,2,1) = (a(pos+off(1)+off(2)+off(3)) - a(pos-off(1)+off(2)+off(3)) - a(pos+off(1)-off(2)+off(3)) + a(pos-off(1)-off(2)+of&
  &f(3)) - a(pos+off(1)+off(2)-off(3)) + a(pos-off(1)+off(2)-off(3)) + a(pos+off(1)-off(2)-off(3)) - a(pos-off(1)-off(2)-off(3))) /&
  & (8*dx(1)*dx(2)*dx(3))
       f(1,3,1) = f(3,1,1)
       f(2,3,1) = f(3,2,1)
       f(3,3,1) = (a(pos+off(1)+off(3)) - 2*a(pos+off(1)) + a(pos+off(1)-off(3)) - a(pos-off(1)+off(3)) + 2*a(pos-off(1)) - a(pos-o&
  &ff(1)-off(3))) / (2*dx(1)*dx(3)*dx(3))
       f(:,1,2) = f(:,2,1)
       f(1,2,2) = f(2,2,1)
       f(2,2,2) = (a(pos+2*off(2)) - 2*a(pos+off(2)) + 2*a(pos-off(2)) - a(pos-2*off(2))) / (2*dx(2)**3)
       f(3,2,2) = (a(pos+off(2)+off(3)) - 2*a(pos+off(3)) + a(pos-off(2)+off(3)) - a(pos+off(2)-off(3)) + 2*a(pos-off(3)) - a(pos-o&
  &ff(2)-off(3))) / (2*dx(2)*dx(2)*dx(3))
       f(1,3,2) = f(3,1,2)
       f(2,3,2) = f(3,2,2)
       f(3,3,2) = (a(pos+off(2)+off(3)) - 2*a(pos+off(2)) + a(pos+off(2)-off(3)) - a(pos-off(2)+off(3)) + 2*a(pos-off(2)) - a(pos-o&
  &ff(2)-off(3))) / (2*dx(2)*dx(3)*dx(3))
       f(:,1,3) = f(:,3,1)
       f(:,2,3) = f(:,3,2)
       f(1,3,3) = f(3,1,3)
       f(2,3,3) = f(3,2,3)
       f(3,3,3) = (a(pos+2*off(3)) - 2*a(pos+off(3)) + 2*a(pos-off(3)) - a(pos-2*off(3))) / (2*dx(3)**3)
    case (4)
       
       f(1,1,1) = (a(pos-3*off(1)) - 8*a(pos-2*off(1)) + 13*a(pos-off(1)) - 13*a(pos+off(1)) + 8*a(pos+2*off(1)) - a(pos+3*off(1)))&
  & / (8*dx(1)**3)
       
       
       f(2,1,1) = (+   a(pos-2*off(1)-2*off(2)) -  16*a(pos-off(1)-2*off(2)) +  30*a(pos-2*off(2)) -  16*a(pos+off(1)-2*off(2)) +  &
  & a(pos+2*off(1)-2*off(2)) &
            &      - 8*a(pos-2*off(1)-  off(2)) + 128*a(pos-off(1)-  off(2)) - 240*a(pos-  off(2)) + 128*a(pos+off(1)-  off(2)) - 8&
  &*a(pos+2*off(1)-  off(2)) &
            &      + 8*a(pos-2*off(1)+  off(2)) - 128*a(pos-off(1)+  off(2)) + 240*a(pos+  off(2)) - 128*a(pos+off(1)+  off(2)) + 8&
  &*a(pos+2*off(1)+  off(2)) &
            &      -   a(pos-2*off(1)+2*off(2)) +  16*a(pos-off(1)+2*off(2)) -  30*a(pos+2*off(2)) +  16*a(pos+off(1)+2*off(2)) -  &
  & a(pos+2*off(1)+2*off(2))) / (144*dx(1)**2*dx(2))
       f(3,1,1) = (+   a(pos-2*off(1)-2*off(3)) -  16*a(pos-off(1)-2*off(3)) +  30*a(pos-2*off(3)) -  16*a(pos+off(1)-2*off(3)) +  &
  & a(pos+2*off(1)-2*off(3)) &
            &      - 8*a(pos-2*off(1)-  off(3)) + 128*a(pos-off(1)-  off(3)) - 240*a(pos-  off(3)) + 128*a(pos+off(1)-  off(3)) - 8&
  &*a(pos+2*off(1)-  off(3)) &
            &      + 8*a(pos-2*off(1)+  off(3)) - 128*a(pos-off(1)+  off(3)) + 240*a(pos+  off(3)) - 128*a(pos+off(1)+  off(3)) + 8&
  &*a(pos+2*off(1)+  off(3)) &
            &      -   a(pos-2*off(1)+2*off(3)) +  16*a(pos-off(1)+2*off(3)) -  30*a(pos+2*off(3)) +  16*a(pos+off(1)+2*off(3)) -  &
  & a(pos+2*off(1)+2*off(3))) / (144*dx(1)**2*dx(3))
       f(1,2,1) = f(2,1,1)
       f(2,2,1) = (+   a(pos-2*off(2)-2*off(1)) -  16*a(pos-off(2)-2*off(1)) +  30*a(pos-2*off(1)) -  16*a(pos+off(2)-2*off(1)) +  &
  & a(pos+2*off(2)-2*off(1)) &
            &      - 8*a(pos-2*off(2)-  off(1)) + 128*a(pos-off(2)-  off(1)) - 240*a(pos-  off(1)) + 128*a(pos+off(2)-  off(1)) - 8&
  &*a(pos+2*off(2)-  off(1)) &
            &      + 8*a(pos-2*off(2)+  off(1)) - 128*a(pos-off(2)+  off(1)) + 240*a(pos+  off(1)) - 128*a(pos+off(2)+  off(1)) + 8&
  &*a(pos+2*off(2)+  off(1)) &
            &      -   a(pos-2*off(2)+2*off(1)) +  16*a(pos-off(2)+2*off(1)) -  30*a(pos+2*off(1)) +  16*a(pos+off(2)+2*off(1)) -  &
  & a(pos+2*off(2)+2*off(1))) / (144*dx(2)**2*dx(1))
       f(3,2,1) = (-     a(pos-2*off(1)-2*off(2)-2*off(3)) +   8*a(pos-off(1)-2*off(2)-2*off(3)) -   8*a(pos+off(1)-2*off(2)-2*off(&
  &3)) +     a(pos+2*off(1)-2*off(2)-2*off(3)) &
            &      +   8*a(pos-2*off(1)-  off(2)-2*off(3)) -  64*a(pos-off(1)-  off(2)-2*off(3)) +  64*a(pos+off(1)-  off(2)-2*off(&
  &3)) -   8*a(pos+2*off(1)-  off(2)-2*off(3)) &
            &      -   8*a(pos-2*off(1)+  off(2)-2*off(3)) +  64*a(pos-off(1)+  off(2)-2*off(3)) -  64*a(pos+off(1)+  off(2)-2*off(&
  &3)) +   8*a(pos+2*off(1)+  off(2)-2*off(3)) &
            &      +     a(pos-2*off(1)+2*off(2)-2*off(3)) -   8*a(pos-off(1)+2*off(2)-2*off(3)) +   8*a(pos+off(1)+2*off(2)-2*off(&
  &3)) -     a(pos+2*off(1)+2*off(2)-2*off(3)) &
            &      +   8*a(pos-2*off(1)-2*off(2)-  off(3)) -  64*a(pos-off(1)-2*off(2)-  off(3)) +  64*a(pos+off(1)-2*off(2)-  off(&
  &3)) -   8*a(pos+2*off(1)-2*off(2)-  off(3)) &
            &      -  64*a(pos-2*off(1)-  off(2)-  off(3)) + 512*a(pos-off(1)-  off(2)-  off(3)) - 512*a(pos+off(1)-  off(2)-  off(&
  &3)) +  64*a(pos+2*off(1)-  off(2)-  off(3)) &
            &      +  64*a(pos-2*off(1)+  off(2)-  off(3)) - 512*a(pos-off(1)+  off(2)-  off(3)) + 512*a(pos+off(1)+  off(2)-  off(&
  &3)) -  64*a(pos+2*off(1)+  off(2)-  off(3)) &
            &      -   8*a(pos-2*off(1)+2*off(2)-  off(3)) +  64*a(pos-off(1)+2*off(2)-  off(3)) -  64*a(pos+off(1)+2*off(2)-  off(&
  &3)) +   8*a(pos+2*off(1)+2*off(2)-  off(3)) &
            &      -   8*a(pos-2*off(1)-2*off(2)+  off(3)) +  64*a(pos-off(1)-2*off(2)+  off(3)) -  64*a(pos+off(1)-2*off(2)+  off(&
  &3)) +   8*a(pos+2*off(1)-2*off(2)+  off(3)) &
            &      +  64*a(pos-2*off(1)-  off(2)+  off(3)) - 512*a(pos-off(1)-  off(2)+  off(3)) + 512*a(pos+off(1)-  off(2)+  off(&
  &3)) -  64*a(pos+2*off(1)-  off(2)+  off(3)) &
            &      -  64*a(pos-2*off(1)+  off(2)+  off(3)) + 512*a(pos-off(1)+  off(2)+  off(3)) - 512*a(pos+off(1)+  off(2)+  off(&
  &3)) +  64*a(pos+2*off(1)+  off(2)+  off(3)) &
            &      +   8*a(pos-2*off(1)+2*off(2)+  off(3)) -  64*a(pos-off(1)+2*off(2)+  off(3)) +  64*a(pos+off(1)+2*off(2)+  off(&
  &3)) -   8*a(pos+2*off(1)+2*off(2)+  off(3)) &
            &      +     a(pos-2*off(1)-2*off(2)+2*off(3)) -   8*a(pos-off(1)-2*off(2)+2*off(3)) +   8*a(pos+off(1)-2*off(2)+2*off(&
  &3)) -     a(pos+2*off(1)-2*off(2)+2*off(3)) &
            &      -   8*a(pos-2*off(1)-  off(2)+2*off(3)) +  64*a(pos-off(1)-  off(2)+2*off(3)) -  64*a(pos+off(1)-  off(2)+2*off(&
  &3)) +   8*a(pos+2*off(1)-  off(2)+2*off(3)) &
            &      +   8*a(pos-2*off(1)+  off(2)+2*off(3)) -  64*a(pos-off(1)+  off(2)+2*off(3)) +  64*a(pos+off(1)+  off(2)+2*off(&
  &3)) -   8*a(pos+2*off(1)+  off(2)+2*off(3)) &
            &      -     a(pos-2*off(1)+2*off(2)+2*off(3)) +   8*a(pos-off(1)+2*off(2)+2*off(3)) -   8*a(pos+off(1)+2*off(2)+2*off(&
  &3)) +     a(pos+2*off(1)+2*off(2)+2*off(3))) / (512*dx(1)*dx(2)*dx(3))
       f(1,3,1) = f(3,1,1)
       f(2,3,1) = f(3,2,1)
       f(3,3,1) = (+   a(pos-2*off(3)-2*off(1)) -  16*a(pos-off(3)-2*off(1)) +  30*a(pos-2*off(1)) -  16*a(pos+off(3)-2*off(1)) +  &
  & a(pos+2*off(3)-2*off(1)) &
            &      - 8*a(pos-2*off(3)-  off(1)) + 128*a(pos-off(3)-  off(1)) - 240*a(pos-  off(1)) + 128*a(pos+off(3)-  off(1)) - 8&
  &*a(pos+2*off(3)-  off(1)) &
            &      + 8*a(pos-2*off(3)+  off(1)) - 128*a(pos-off(3)+  off(1)) + 240*a(pos+  off(1)) - 128*a(pos+off(3)+  off(1)) + 8&
  &*a(pos+2*off(3)+  off(1)) &
            &      -   a(pos-2*off(3)+2*off(1)) +  16*a(pos-off(3)+2*off(1)) -  30*a(pos+2*off(1)) +  16*a(pos+off(3)+2*off(1)) -  &
  & a(pos+2*off(3)+2*off(1))) / (144*dx(3)**2*dx(1))
       f(:,1,2) = f(:,2,1)
       f(1,2,2) = f(2,2,1)
       f(2,2,2) = (a(pos-3*off(2)) - 8*a(pos-2*off(2)) + 13*a(pos-off(2)) - 13*a(pos+off(2)) + 8*a(pos+2*off(2)) - a(pos+3*off(2)))&
  & / (8*dx(2)**3)
       f(3,2,2) = (+   a(pos-2*off(2)-2*off(3)) -  16*a(pos-off(2)-2*off(3)) +  30*a(pos-2*off(3)) -  16*a(pos+off(2)-2*off(3)) +  &
  & a(pos+2*off(2)-2*off(3)) &
            &      - 8*a(pos-2*off(2)-  off(3)) + 128*a(pos-off(2)-  off(3)) - 240*a(pos-  off(3)) + 128*a(pos+off(2)-  off(3)) - 8&
  &*a(pos+2*off(2)-  off(3)) &
            &      + 8*a(pos-2*off(2)+  off(3)) - 128*a(pos-off(2)+  off(3)) + 240*a(pos+  off(3)) - 128*a(pos+off(2)+  off(3)) + 8&
  &*a(pos+2*off(2)+  off(3)) &
            &      -   a(pos-2*off(2)+2*off(3)) +  16*a(pos-off(2)+2*off(3)) -  30*a(pos+2*off(3)) +  16*a(pos+off(2)+2*off(3)) -  &
  & a(pos+2*off(2)+2*off(3))) / (144*dx(2)**2*dx(3))
       f(1,3,2) = f(3,1,2)
       f(2,3,2) = f(3,2,2)
       f(3,3,2) = (+   a(pos-2*off(3)-2*off(2)) -  16*a(pos-off(3)-2*off(2)) +  30*a(pos-2*off(2)) -  16*a(pos+off(3)-2*off(2)) +  &
  & a(pos+2*off(3)-2*off(2)) &
            &      - 8*a(pos-2*off(3)-  off(2)) + 128*a(pos-off(3)-  off(2)) - 240*a(pos-  off(2)) + 128*a(pos+off(3)-  off(2)) - 8&
  &*a(pos+2*off(3)-  off(2)) &
            &      + 8*a(pos-2*off(3)+  off(2)) - 128*a(pos-off(3)+  off(2)) + 240*a(pos+  off(2)) - 128*a(pos+off(3)+  off(2)) + 8&
  &*a(pos+2*off(3)+  off(2)) &
            &      -   a(pos-2*off(3)+2*off(2)) +  16*a(pos-off(3)+2*off(2)) -  30*a(pos+2*off(2)) +  16*a(pos+off(3)+2*off(2)) -  &
  & a(pos+2*off(3)+2*off(2))) / (144*dx(3)**2*dx(2))
       f(:,1,3) = f(:,3,1)
       f(:,2,3) = f(:,3,2)
       f(1,3,3) = f(3,1,3)
       f(2,3,3) = f(3,2,3)
       f(3,3,3) = (a(pos-3*off(3)) - 8*a(pos-2*off(3)) + 13*a(pos-off(3)) - 13*a(pos+off(3)) + 8*a(pos+2*off(3)) - a(pos+3*off(3)))&
  & / (8*dx(3)**3)
    case default
       call CCTK_Warn(0,177,"pointwise.F90","TGRtensor", "Unsupported finite differencing order")
    end select
  end subroutine get_derivs3

  subroutine calc_position (shape, i,j,k, pos)
    integer, intent(in)  :: shape(3)
    integer, intent(in)  :: i,j,k
    integer, intent(out) :: pos
    pos = 1 + i-1 + shape(1) * (j-1 + shape(2) * (k-1))
  end subroutine calc_position
  subroutine calc_offsets (shape, off)
    integer, intent(in)  :: shape(3)
    integer, intent(out) :: off(3)
    off(1) = 1
    off(2) = shape(1)
    off(3) = shape(1) * shape(2)
  end subroutine calc_offsets
  subroutine get_scalar (a, f, pos)
    REAL*8, intent(in)  :: a(*)
    REAL*8, intent(out) :: f
    integer,   intent(in)  :: pos
    f = a(pos)
  end subroutine get_scalar
  subroutine get_vector (ax,ay,az, f, pos)
    REAL*8, intent(in)  :: ax(*),ay(*),az(*)
    REAL*8, intent(out) :: f(3)
    integer,   intent(in)  :: pos
    f(1) = ax(pos)
    f(2) = ay(pos)
    f(3) = az(pos)
  end subroutine get_vector
  subroutine get_tensor (axx,axy,axz,ayy,ayz,azz, f, pos)
    REAL*8, intent(in)  :: axx(*),axy(*),axz(*),ayy(*),ayz(*),azz(*)
    REAL*8, intent(out) :: f(3,3)
    integer,   intent(in)  :: pos
    f(1,1) = axx(pos)
    f(1,2) = axy(pos)
    f(1,3) = axz(pos)
    f(2,1) = axy(pos)
    f(2,2) = ayy(pos)
    f(2,3) = ayz(pos)
    f(3,1) = axz(pos)
    f(3,2) = ayz(pos)
    f(3,3) = azz(pos)
  end subroutine get_tensor
  subroutine get_connections (&
       gammaxxx,gammaxxy,gammaxxz,gammaxyy,gammaxyz,gammaxzz, &
       gammayxx,gammayxy,gammayxz,gammayyy,gammayyz,gammayzz, &
       gammazxx,gammazxy,gammazxz,gammazyy,gammazyz,gammazzz, gamma, pos)
    REAL*8, intent(in)  :: gammaxxx(*),gammaxxy(*),gammaxxz(*)
    REAL*8, intent(in)  :: gammaxyy(*),gammaxyz(*),gammaxzz(*)
    REAL*8, intent(in)  :: gammayxx(*),gammayxy(*),gammayxz(*)
    REAL*8, intent(in)  :: gammayyy(*),gammayyz(*),gammayzz(*)
    REAL*8, intent(in)  :: gammazxx(*),gammazxy(*),gammazxz(*)
    REAL*8, intent(in)  :: gammazyy(*),gammazyz(*),gammazzz(*)
    REAL*8, intent(out) :: gamma(3,3,3)
    integer,   intent(in)  :: pos
    gamma(1,1,1) = gammaxxx(pos)
    gamma(1,1,2) = gammaxxy(pos)
    gamma(1,1,3) = gammaxxz(pos)
    gamma(1,2,1) = gammaxxy(pos)
    gamma(1,2,2) = gammaxyy(pos)
    gamma(1,2,3) = gammaxyz(pos)
    gamma(1,3,1) = gammaxxz(pos)
    gamma(1,3,2) = gammaxyz(pos)
    gamma(1,3,3) = gammaxzz(pos)
    gamma(2,1,1) = gammayxx(pos)
    gamma(2,1,2) = gammayxy(pos)
    gamma(2,1,3) = gammayxz(pos)
    gamma(2,2,1) = gammayxy(pos)
    gamma(2,2,2) = gammayyy(pos)
    gamma(2,2,3) = gammayyz(pos)
    gamma(2,3,1) = gammayxz(pos)
    gamma(2,3,2) = gammayyz(pos)
    gamma(2,3,3) = gammayzz(pos)
    gamma(3,1,1) = gammazxx(pos)
    gamma(3,1,2) = gammazxy(pos)
    gamma(3,1,3) = gammazxz(pos)
    gamma(3,2,1) = gammazxy(pos)
    gamma(3,2,2) = gammazyy(pos)
    gamma(3,2,3) = gammazyz(pos)
    gamma(3,3,1) = gammazxz(pos)
    gamma(3,3,2) = gammazyz(pos)
    gamma(3,3,3) = gammazzz(pos)
  end subroutine get_connections
  subroutine set_scalar (f, a, pos)
    REAL*8, intent(in) :: f
    REAL*8             :: a(*)
    integer,   intent(in) :: pos
    a(pos) = f
  end subroutine set_scalar
  subroutine set_vector (f, ax,ay,az, pos)
    REAL*8, intent(in) :: f(3)
    REAL*8             :: ax(*),ay(*),az(*)
    integer,   intent(in) :: pos
    ax(pos) = f(1)
    ay(pos) = f(2)
    az(pos) = f(3)
  end subroutine set_vector
  subroutine set_tensor (f, axx,axy,axz,ayy,ayz,azz, pos)
    REAL*8, intent(in) :: f(3,3)
    REAL*8             :: axx(*),axy(*),axz(*),ayy(*),ayz(*),azz(*)
    integer,   intent(in) :: pos
    axx(pos) = f(1,1)
    axy(pos) = f(1,2)
    axz(pos) = f(1,3)
    ayy(pos) = f(2,2)
    ayz(pos) = f(2,3)
    azz(pos) = f(3,3)
  end subroutine set_tensor
  subroutine set_connections (gamma, &
       gammaxxx,gammaxxy,gammaxxz,gammaxyy,gammaxyz,gammaxzz, &
       gammayxx,gammayxy,gammayxz,gammayyy,gammayyz,gammayzz, &
       gammazxx,gammazxy,gammazxz,gammazyy,gammazyz,gammazzz, pos)
    REAL*8, intent(in) :: gamma(3,3,3)
    REAL*8             :: gammaxxx(*),gammaxxy(*),gammaxxz(*)
    REAL*8             :: gammaxyy(*),gammaxyz(*),gammaxzz(*)
    REAL*8             :: gammayxx(*),gammayxy(*),gammayxz(*)
    REAL*8             :: gammayyy(*),gammayyz(*),gammayzz(*)
    REAL*8             :: gammazxx(*),gammazxy(*),gammazxz(*)
    REAL*8             :: gammazyy(*),gammazyz(*),gammazzz(*)
    integer,   intent(in)  :: pos
    gammaxxx(pos) = gamma(1,1,1)
    gammaxxy(pos) = gamma(1,1,2)
    gammaxxz(pos) = gamma(1,1,3)
    gammaxyy(pos) = gamma(1,2,2)
    gammaxyz(pos) = gamma(1,2,3)
    gammaxzz(pos) = gamma(1,3,3)
    gammayxx(pos) = gamma(2,1,1)
    gammayxy(pos) = gamma(2,1,2)
    gammayxz(pos) = gamma(2,1,3)
    gammayyy(pos) = gamma(2,2,2)
    gammayyz(pos) = gamma(2,2,3)
    gammayzz(pos) = gamma(2,3,3)
    gammazxx(pos) = gamma(3,1,1)
    gammazxy(pos) = gamma(3,1,2)
    gammazxz(pos) = gamma(3,1,3)
    gammazyy(pos) = gamma(3,2,2)
    gammazyz(pos) = gamma(3,2,3)
    gammazzz(pos) = gamma(3,3,3)
  end subroutine set_connections
  subroutine get_scalarderivs (a, f, pos, off, dx, order)
    REAL*8, intent(in)            :: a(*)
    REAL*8, intent(out)           :: f(3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    call get_derivs (a, f, pos, off, dx, order)
  end subroutine get_scalarderivs
  subroutine get_vectorderivs (ax,ay,az, f, pos, off, dx, order)
    REAL*8, intent(in)            :: ax(*),ay(*),az(*)
    REAL*8, intent(out)           :: f(3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    REAL*8 :: fx(3),fy(3),fz(3)
    call get_derivs (ax, fx, pos, off, dx, order)
    call get_derivs (ay, fy, pos, off, dx, order)
    call get_derivs (az, fz, pos, off, dx, order)
    f(1,:) = fx
    f(2,:) = fy
    f(3,:) = fz
  end subroutine get_vectorderivs
  subroutine get_tensorderivs (axx,axy,axz,ayy,ayz,azz, f, pos, off, dx, order)
    REAL*8, intent(in)            :: axx(*),axy(*),axz(*),ayy(*),ayz(*),azz(*)
    REAL*8, intent(out)           :: f(3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    REAL*8 :: fxx(3),fxy(3),fxz(3),fyy(3),fyz(3),fzz(3)
    call get_derivs (axx, fxx, pos, off, dx, order)
    call get_derivs (axy, fxy, pos, off, dx, order)
    call get_derivs (axz, fxz, pos, off, dx, order)
    call get_derivs (ayy, fyy, pos, off, dx, order)
    call get_derivs (ayz, fyz, pos, off, dx, order)
    call get_derivs (azz, fzz, pos, off, dx, order)
    f(1,1,:) = fxx
    f(1,2,:) = fxy
    f(1,3,:) = fxz
    f(2,1,:) = fxy
    f(2,2,:) = fyy
    f(2,3,:) = fyz
    f(3,1,:) = fxz
    f(3,2,:) = fyz
    f(3,3,:) = fzz
  end subroutine get_tensorderivs
  subroutine get_scalarderivs2 (a, f, pos, off, dx, order)
    REAL*8, intent(in)            :: a(*)
    REAL*8, intent(out)           :: f(3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    call get_derivs2 (a, f, pos, off, dx, order)
  end subroutine get_scalarderivs2
  subroutine get_vectorderivs2 (ax,ay,az, f, pos, off, dx, order)
    REAL*8, intent(in)            :: ax(*),ay(*),az(*)
    REAL*8, intent(out)           :: f(3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    REAL*8 :: fx(3,3),fy(3,3),fz(3,3)
    call get_derivs2 (ax, fx, pos, off, dx, order)
    call get_derivs2 (ay, fy, pos, off, dx, order)
    call get_derivs2 (az, fz, pos, off, dx, order)
    f(1,:,:) = fx
    f(2,:,:) = fy
    f(3,:,:) = fz
  end subroutine get_vectorderivs2
  subroutine get_tensorderivs2 (axx,axy,axz,ayy,ayz,azz, f, pos, off, dx, order)
    REAL*8, intent(in)            :: axx(*),axy(*),axz(*),ayy(*),ayz(*),azz(*)
    REAL*8, intent(out)           :: f(3,3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    REAL*8 :: fxx(3,3),fxy(3,3),fxz(3,3),fyy(3,3),fyz(3,3),fzz(3,3)
    call get_derivs2 (axx, fxx, pos, off, dx, order)
    call get_derivs2 (axy, fxy, pos, off, dx, order)
    call get_derivs2 (axz, fxz, pos, off, dx, order)
    call get_derivs2 (ayy, fyy, pos, off, dx, order)
    call get_derivs2 (ayz, fyz, pos, off, dx, order)
    call get_derivs2 (azz, fzz, pos, off, dx, order)
    f(1,1,:,:) = fxx
    f(1,2,:,:) = fxy
    f(1,3,:,:) = fxz
    f(2,1,:,:) = fxy
    f(2,2,:,:) = fyy
    f(2,3,:,:) = fyz
    f(3,1,:,:) = fxz
    f(3,2,:,:) = fyz
    f(3,3,:,:) = fzz
  end subroutine get_tensorderivs2
  subroutine get_scalarderivs3 (a, f, pos, off, dx, order)
    REAL*8, intent(in)            :: a(*)
    REAL*8, intent(out)           :: f(3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    call get_derivs3 (a, f, pos, off, dx, order)
  end subroutine get_scalarderivs3
  subroutine get_vectorderivs3 (ax,ay,az, f, pos, off, dx, order)
    REAL*8, intent(in)            :: ax(*),ay(*),az(*)
    REAL*8, intent(out)           :: f(3,3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    REAL*8 :: fx(3,3,3),fy(3,3,3),fz(3,3,3)
    call get_derivs3 (ax, fx, pos, off, dx, order)
    call get_derivs3 (ay, fy, pos, off, dx, order)
    call get_derivs3 (az, fz, pos, off, dx, order)
    f(1,:,:,:) = fx
    f(2,:,:,:) = fy
    f(3,:,:,:) = fz
  end subroutine get_vectorderivs3
  subroutine get_tensorderivs3 (axx,axy,axz,ayy,ayz,azz, f, pos, off, dx, order)
    REAL*8, intent(in)            :: axx(*),axy(*),axz(*),ayy(*),ayz(*),azz(*)
    REAL*8, intent(out)           :: f(3,3,3,3,3)
    integer,   intent(in)            :: pos, off(3)
    REAL*8, intent(in)            :: dx(3)
    integer,   intent(in),  optional :: order
    REAL*8 :: fxx(3,3,3),fxy(3,3,3),fxz(3,3,3),&
         &       fyy(3,3,3),fyz(3,3,3),fzz(3,3,3)
    call get_derivs3 (axx, fxx, pos, off, dx, order)
    call get_derivs3 (axy, fxy, pos, off, dx, order)
    call get_derivs3 (axz, fxz, pos, off, dx, order)
    call get_derivs3 (ayy, fyy, pos, off, dx, order)
    call get_derivs3 (ayz, fyz, pos, off, dx, order)
    call get_derivs3 (azz, fzz, pos, off, dx, order)
    f(1,1,:,:,:) = fxx
    f(1,2,:,:,:) = fxy
    f(1,3,:,:,:) = fxz
    f(2,1,:,:,:) = fxy
    f(2,2,:,:,:) = fyy
    f(2,3,:,:,:) = fyz
    f(3,1,:,:,:) = fxz
    f(3,2,:,:,:) = fyz
    f(3,3,:,:,:) = fzz
  end subroutine get_tensorderivs3
end module pointwise
