!----------------------------------------------------------------------
!     Copyright (c) 2001 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------

program n2test

  use n2pack
  implicit none

  integer,parameter  :: im=16, jm=16    ! 格子点の設定(X,Y)
  integer,parameter  :: km=5,  lm=5     ! 切断波数の設定(X,Y)

  double precision,parameter :: pi=3.141592653589793
  double precision   :: xlength=2*pi, ylength=2*pi   ! 領域の大きさ

  double precision, dimension(0:jm-1,0:im-1) :: gg_data
  double precision, dimension(0:jm-1,0:im-1) :: x, y
  double precision, dimension(-lm:lm,-km:km) :: ee_data

  integer          :: i, j, k, l

  double precision, parameter :: eps=1e-7    ! 0 に近い数の閾値

  do i=0,im-1
     do j=0,jm-1
        x(j,i)=xlength/im*i ; y(j,i)=ylength/jm*j
     enddo
  enddo

  gg_data = sin(2*pi*x/xlength)*sin(2*pi*y/ylength)
     ! 変換      : ( 1 -1  0.25), ( 1 1 -0.25)
     ! X 微分    : (-1 -1 -0.25), (-1 1  0.25)
     ! Y 微分    : ( 1 -1  0.25), ( 1 1  0.25)
     ! Laplacian : ( 1 -1 -0.5) , ( 1 1 -0.5)
  !gg_data = 1.0

  call n2initial(im,jm,km,lm,xlength,ylength)

  write (6,*) 'Transform(k,l,value)'
  ee_data = ee_gg(gg_data)
  do k=-km,km
     do l=-lm,lm
        if ( abs(ee_data(l,k)) .gt. eps ) then
           write (6,*) k, l, ee_data(l,k)
        endif
     enddo
  enddo

!!$  write (6,*) 'InvTransform(i,j,value)'
!!$  gg_data = gg_ee(ee_data)
!!$  do i=0,im-1
!!$     do j=0,jm-1
!!$        if ( abs(gg_data(j,i)) .gt. eps ) then
!!$           write (6,*) i, j, gg_data(j,i)
!!$        endif
!!$     enddo
!!$  enddo

  write (6,*) 'X derivative(k,l,value)'
  ee_data = ee_dx_ee(ee_data)
  do k=-km,km
     do l=-lm,lm
        if ( abs(ee_data(l,k)) .gt. eps ) then
           write (6,*)  k, l, ee_data(l,k)
        endif
     enddo
  enddo

  write (6,*) 'Y derivative(k,l,value)'
  ee_data = ee_dy_ee(ee_data)
  do k=-km,km
     do l=-lm,lm
        if ( abs(ee_data(l,k)) .gt. eps ) then
           write (6,*) k, l, ee_data(l,k)
        endif
     enddo
  enddo

  write (6,*) 'Laplacian(k,l,value)'
  ee_data = ee_lapla_ee(ee_data)
  do k=-km,km
     do l=-lm,lm
        if ( abs(ee_data(l,k)) .gt. eps ) then
           write (6,*) k, l, ee_data(l,k)
        endif
     enddo
  enddo

  write (6,*) 'Jacobian(k,l,value)'
  ee_data = ee_jacobian_ee_ee(ee_data,ee_data)
  do k=-km,km
     do l=-lm,lm
        if ( abs(ee_data(l,k)) .gt. eps ) then
           write (6,*) k, l, ee_data(l,k)
        endif
     enddo
  enddo

  write (6,*) 'Jacobian_Zeta(k,l,value)'
  ee_data = ee_jacobianz_ee(ee_data)
  do k=-km,km
     do l=-lm,lm
        if ( abs(ee_data(l,k)) .gt. eps ) then
           write (6,*) k, l, ee_data(l,k)
        endif
     enddo
  enddo

  stop
  end
