      module types
      integer ,  parameter:: I4B=SELECTED_INT_KIND (9) 
      integer ,  parameter:: I2B=SELECTED_INT_KIND (4) 
      integer ,  parameter:: I1B=SELECTED_INT_KIND (2) 
      integer ,  parameter:: SP=KIND (1.0D0) 
      end module


      module hpfprocessors
!HPF$      processors PROC(4)
      end module


      module diff_interface
      interface 
         subroutine diff_x(nx, ny, nz, h, f, df)
         use types
         use hpfprocessors
         integer (I4B):: nx,ny,nz
         real (SP):: h
         real (SP),  dimension(:,:,:),intent(in):: f 
         real (SP),  dimension(:,:,:),intent(out):: df 
!HPF$      distribute * (*,*,block) onto * PROC :: f
!HPF$      align with * f :: df
         end subroutine

         subroutine diff_y(nx, ny, nz, h, f, df)
         use types
         use hpfprocessors
         integer (I4B):: nx,ny,nz
         real (SP):: h
         real (SP),  dimension(:,:,:),intent(in):: f 
         real (SP),  dimension(:,:,:),intent(out):: df 
!HPF$      distribute * (*,*,block) onto * PROC :: f
!HPF$      align with * f :: df
         end subroutine

         subroutine diff_z(nx, ny, nz, h, f, df)
         use types
         use hpfprocessors
         integer (I4B):: nx,ny,nz
         real (SP):: h
         real (SP),  dimension(:,:,:),intent(in):: f 
         real (SP),  dimension(:,:,:),intent(out):: df 
!HPF$      distribute * (*,*,block) onto * PROC :: f
!HPF$      align with * f :: df
         end subroutine

      end interface
      end module


      subroutine tensors(g11, g12, g13, g22, g23, g33, gup11, gup12, gup&
     &13, gup22, gup23, gup33, c111, c112, c113, c122, c123, c133, c211,&
     & c212, c213, c222, c223, c233, c311, c312, c313, c322, c323, c333,&
     & r11, r12, r13, r22, r23, r33, nx, ny, nz, h)
      use hpfprocessors
      use types
      real (SP),  dimension(:,:,:),intent(in):: g11,g12,g13,g22,g23,g33 

      real (SP),  dimension(:,:,:),intent(out):: gup11,gup12,gup13,gup22&
     &,gup23,gup33 
      real (SP),  dimension(:,:,:),intent(out):: c111,c112,c113,c122,c12&
     &3,c133 
      real (SP),  dimension(:,:,:),intent(out):: c211,c212,c213,c222,c22&
     &3,c233 
      real (SP),  dimension(:,:,:),intent(out):: c311,c312,c313,c322,c32&
     &3,c333 
      real (SP),  dimension(:,:,:),intent(out):: r11,r12,r13,r22,r23,r33&
     & 
!HPF$      distribute g11 * (*,*,block) onto * PROC
!HPF$      align with * g11 :: g12,g13,g22,g23,g33
!HPF$      align with * g11 :: gup11,gup12,gup13,gup22,gup23,gup33
!HPF$      align with * g11 :: c111,c112,c113,c122,c123,c133
!HPF$      align with * g11 :: c211,c212,c213,c222,c223,c233
!HPF$      align with * g11 :: c311,c312,c313,c322,c323,c333
!HPF$      align with * g11 :: r11,r12,r13,r22,r23,r33
      integer (I4B):: nx,ny,nz
      real (SP):: h
      interface 
         subroutine inverse(g11, g12, g13, g22, g23, g33, gup11, gup12, &
     &gup13, gup22, gup23, gup33)
         use hpfprocessors
         use types
         real (SP),  dimension(:,:,:),intent(in):: g11,g12,g13,g22,g23,g&
     &33 
         real (SP),  dimension(:,:,:),intent(out):: gup11,gup12,gup13,gu&
     &p22,gup23,gup33 
!HPF$      distribute g11 * (*,*,block) onto * PROC
!HPF$      align with * g11 :: g12,g13,g22,g23,g33
!HPF$      align with * g11 :: gup11,gup12,gup13,gup22,gup23,gup33
         end subroutine

         subroutine connect0(g11, g12, g13, g22, g23, g33, gup11, gup12,&
     & gup13, gup22, gup23, gup33, c111, c112, c113, c122, c123, c133, c&
     &211, c212, c213, c222, c223, c233, c311, c312, c313, c322, c323, c&
     &333, nx, ny, nz, h)
         use types
         use hpfprocessors
         use diff_interface
         real (SP),  dimension(:,:,:),intent(in):: g11,g12,g13,g22,g23,g&
     &33 
         real (SP),  dimension(:,:,:),intent(in):: gup11,gup12,gup13,gup&
     &22,gup23,gup33 
         real (SP),  dimension(:,:,:),intent(out):: c111,c112,c113,c122,&
     &c123,c133 
         real (SP),  dimension(:,:,:),intent(out):: c211,c212,c213,c222,&
     &c223,c233 
         real (SP),  dimension(:,:,:),intent(out):: c311,c312,c313,c322,&
     &c323,c333 
!HPF$      distribute g11 * (*,*,block) onto * PROC
!HPF$      align with * g11 :: g12,g13,g22,g23,g33
!HPF$      align with * g11 :: gup11,gup12,gup13,gup22,gup23,gup33
!HPF$      align with * g11 :: c111,c112,c113,c122,c123,c133
!HPF$      align with * g11 :: c211,c212,c213,c222,c223,c233
!HPF$      align with * g11 :: c311,c312,c313,c322,c323,c333
         integer (I4B):: nx,ny,nz
         real (SP):: h
         end subroutine

         subroutine riccidd(r11, r12, r13, r22, r23, r33, c111, c112, c1&
     &13, c122, c123, c133, c211, c212, c213, c222, c223, c233, c311, c3&
     &12, c313, c322, c323, c333, nx, ny, nz, h)
         use types
         use hpfprocessors
         use diff_interface
         real (SP),  dimension(:,:,:),intent(out):: r11,r12,r13,r22,r23,&
     &r33 
         real (SP),  dimension(:,:,:),intent(in):: c111,c112,c113,c122,c&
     &123,c133 
         real (SP),  dimension(:,:,:),intent(in):: c211,c212,c213,c222,c&
     &223,c233 
         real (SP),  dimension(:,:,:),intent(in):: c311,c312,c313,c322,c&
     &323,c333 
!HPF$      distribute r11 * (*,*,block) onto * PROC
!HPF$      align with * r11 :: r12,r13,r22,r23,r33
!HPF$      align with * r11 :: c111,c112,c113,c122,c123,c133
!HPF$      align with * r11 :: c211,c212,c213,c222,c223,c233
!HPF$      align with * r11 :: c311,c312,c313,c322,c323,c333
         integer (I4B):: nx,ny,nz
         real (SP):: h
         end subroutine

      end interface
      call inverse (g11,g12,g13,g22,g23,g33,gup11,gup12,gup13,gup22,gup2&
     &3,gup33)
      call connect0 (g11,g12,g13,g22,g23,g33,gup11,gup12,gup13,gup22,gup&
     &23,gup33,c111,c112,c113,c122,c123,c133,c211,c212,c213,c222,c223,c2&
     &33,c311,c312,c313,c322,c323,c333,nx,ny,nz,h)
      call riccidd (r11,r12,r13,r22,r23,r33,c111,c112,c113,c122,c123,c13&
     &3,c211,c212,c213,c222,c223,c233,c311,c312,c313,c322,c323,c333,nx,n&
     &y,nz,h)
      return
      end subroutine

