!----------------------------------------------------------------------
!     Copyright (c) 2002 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!$BI=Bj(B  FTPACK/ISPACK-F90 $B%F%9%H%W%m%0%i%`(B
!
!$BMzNr(B  2002/01/25  $BC]9-??0l(B
!
program ftpack_test2d

  use ftrpack
  implicit none
  integer, parameter :: im=8, km=3, nm=3
  real(8), parameter :: xlength=1.0
  real(8), parameter :: eps=1.0D-14
  real(8), parameter :: pi=3.1415926535897932385D0

  real(8), dimension(nm,0:im-1) :: f
  real(8), dimension(nm,0:im-1) :: g_f
  real(8), dimension(nm,-km:km) :: e_f
  real(8), dimension(nm,-km:km) :: e_dfdx
  real(8), dimension(nm,-km:km) :: e_df2dx2

  integer :: k, i, m, n

  call ftrinitial(im,km,xlength)

  f(1,:) = 1
  f(2,:) = sin(2*pi*g_x)
  f(3,:) = cos(4*pi*g_x)

  e_f    = e_g(f)
  g_f    = g_e(e_f)
  e_dfdx   = e_dx_e(e_f)
  e_df2dx2 = e_dx_e(e_dx_e(e_f))

  write(6,*) 'Fourier Transform'
  do n=1,nm
     write(6,*) 'n=',n
     write(6,*) e_f(n,:)
  enddo
  write(6,*) 
  write(6,*) 'Inverse Transform'
  do n=1,nm
     write(6,*) 'n=',n
     write(6,*) g_f(n,:) - f(n,:)
  enddo

  write(6,*) 
  write(6,*) 'Differentiation'
  do n=1,nm
     write(6,*) 'n=',n
     write(6,*) e_dfdx(n,:)
  enddo

end program ftpack_test2d
