      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 connect4(g11, g12, g13, g22, g23, g33, gup11, gup12, gu&
     &p13, gup22, gup23, gup33, c111, c112, c113, c122, c123, c133, c211&
     &, c212, c213, c222, c223, c233, c311, c312, c313, c322, c323, c333&
     &, nx, ny, nz, h)
      use types
      use hpfprocessors
      use diff_interface
      real (SP),  dimension(:,:,:),intent(in):: g11,g12,g13,g22,g23,g33 

      real (SP),  dimension(:,:,:),intent(in):: gup11,gup12,gup13,gup22,&
     &gup23,gup33 
      real (SP),  dimension(:,:,:),intent(inout):: c111,c112,c113,c122,c&
     &123,c133 
      real (SP),  dimension(:,:,:),intent(inout):: c211,c212,c213,c222,c&
     &223,c233 
      real (SP),  dimension(:,:,:),intent(inout):: c311,c312,c313,c322,c&
     &323,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
      real (SP),  dimension(size (g11,1),size (g11,2),size (g11,3)):: t1&
     &1,t12,t13,t21,t22,t23,t31,t32,t33 
!HPF$      align with g11 :: t11,t12,t13,t21,t22,t23,t31,t32,t33
      call diff_x (nx,ny,nz,h,g11,t11)
      call diff_x (nx,ny,nz,h,g12,t12)
      call diff_x (nx,ny,nz,h,g13,t13)
      call diff_x (nx,ny,nz,h,g22,t21)
      call diff_x (nx,ny,nz,h,g23,t22)
      call diff_x (nx,ny,nz,h,g33,t23)
      c111 = c111-(0.5d0*gup11*t11)
      c112 = c112-(0.5d0*gup11*t12)
      c113 = c113-(0.5d0*gup11*t13)
      c122 = c122-(0.5d0*gup11*t21)
      c123 = c123-(0.5d0*gup11*t22)
      c133 = c133-(0.5d0*gup11*t23)
      c211 = c211-(0.5d0*gup12*t11)
      c212 = c212-(0.5d0*gup12*t12)
      c213 = c213-(0.5d0*gup12*t13)
      c222 = c222-(0.5d0*gup12*t21)
      c223 = c223-(0.5d0*gup12*t22)
      c233 = c233-(0.5d0*gup12*t23)
      c311 = c311-(0.5d0*gup13*t11)
      c312 = c312-(0.5d0*gup13*t12)
      c313 = c313-(0.5d0*gup13*t13)
      c322 = c322-(0.5d0*gup13*t21)
      c323 = c323-(0.5d0*gup13*t22)
      c333 = c333-(0.5d0*gup13*t23)
      return
      end subroutine

