module differential
  use CalcParameter
  implicit none
contains
  
  subroutine four_differential(data, deldata)
    real(8),intent(in) :: data(-1:,0:)
    real(8),intent(out) :: deldata(1:,1:)
  
    integer :: i,j,n,m
    n = size(deldata,1)
    m = size(deldata,2)
    
    do j = 1, m
       do i = 1, n
          deldata(i,j) =                     &
               & (                           &
               &   + data(i+2,j)             &
               &   - dble(4)*data(i+1,j)     &
               &   + dble(6)*data(i,j)       &
               &   - dble(4)*data(i-1,j)     &
               &   + data(i-2,j)             &
               & )/(dx**4)
       end do
    end do
    return
  end subroutine four_differential

  
  subroutine two_differential_x(data, deldata)
    real(8), intent(in) :: data(-1:,0:)
    real(8),intent(out) :: deldata(1:,1:)
    integer :: i,j,n,m
    n = size(deldata,1)
    m = size(deldata,2)
    
    do j = 1, m
       do i = 1, n
          deldata(i,j) =                     &
               & (                           &
               &   + data(i+1,j)             &
               &   - dble(2)*data(i,j)       &
               &   + data(i-1,j)             &
               & )/(dx**2)
       end do
    end do
    return
  end subroutine two_differential_x

  
  subroutine two_differential_z(data, deldata)
    real(8), intent(in) :: data(-1:,0:)
    real(8),intent(out) :: deldata(1:,1:)
    integer :: i,j,n,m
    n = size(deldata,1)
    m = size(deldata,2)
    
    do j = 1, m
       do i = 1, n
          deldata(i,j) =                     &
               & (                           &
               &   + data(i,j+1)             &
               &   - dble(2)*data(i,j)       &
               &   + data(i,j-1)             &
               & )/(dz**2)
       end do
    end do
    return
end subroutine two_differential_z



end module differential
