!----------------------------------------------------------------------
!     Copyright (c) 2010--2012 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!
!表題  wtq_mpi_module_sjpack テストプログラム
!      積分・平均計算
!
!履歴  2010/04/18  竹広真一  wt_module_sjpack_integral_test.f90 より改造
!      2011/09/14  竹広真一  MPI 並列化
!      2011/09/14  竹広真一  wtq_mpi_module 用に改造
!      2012/04/02  竹広真一  wtq_mpi_module_sjpack 用に改造
!
program wtq_mpi_sjpack_integral_wt

  use dc_message, only : MessageNotify
  use dc_test, only : AssertEqual
  use wtq_mpi_module_sjpack
  use mpi

  implicit none

  integer,parameter  :: im=32, jm=16         ! 格子点の設定(経度, 緯度, 動径)
  integer,parameter  :: kmo=16, kmi=21       ! 格子点の設定(球殻動径, 球動径)
  integer,parameter  :: nm=10                ! 切断波数の設定(水平)
  integer,parameter  :: lmo=10, lmi=32       ! 切断波数の設定(球殻動径, 球動径)
  real(8),parameter  :: ri=0.5, ro=1.5       ! 内外半径

  real(8), dimension(0:im-1,1:jm,0:kmo)       :: xyz_Data

  real(8), dimension(0:im-1,1:jm)            :: xy_Data
  real(8), dimension(1:jm,0:kmo)              :: yz_Data
  real(8), dimension(0:im-1,0:kmo)            :: xz_Data
  real(8), dimension(0:im-1)                 :: x_Data
  real(8), dimension(1:jm)                   :: y_Data
  real(8), dimension(0:kmo)                   :: z_Data
  real(8)                                    :: Data

  real(8), allocatable :: xvz_Data(:,:,:)

  real(8), allocatable :: xv_Data(:,:)
  real(8), allocatable :: vz_Data(:,:)
  real(8), allocatable :: v_Data(:)

  ! 判定誤差設定
  integer, parameter :: check_digits = 8
  integer, parameter :: ignore = -9

  real(8), parameter  :: pi=3.1415926535897932385D0

  integer :: iproc, np, ierr

 !---------------- MPI スタート ---------------------
  call MPI_INIT(IERR)
  call MPI_COMM_RANK(MPI_COMM_WORLD,IPROC,IERR)
  call MPI_COMM_SIZE(MPI_COMM_WORLD,NP,IERR)

  !============================ 積分(xyz,xvz) ==============================

  call MessageNotify('M','wtq_mpi_module_sjpack_integral_wt_test', &
       'wtq_mpi_module_sjpack wt-integration functions tests')

  call wtq_mpi_Initial(im,jm,kmi,kmo,nm,lmi,lmo,ri,ro)

  allocate(xvz_Data(0:im-1,1:jc,0:kmo))

  allocate(xv_Data(0:im-1,1:jc))
  allocate(vz_Data(1:jc,0:kmo))
  allocate(v_Data(1:jc))

 !---------- 定数 ----------
  xyz_Data = 1.0D0
  xvz_Data = 1.0D0

  yz_Data = 2*pi
  call AssertEqual(&
       message='yz_IntLon_xyz with constant field',                &
       answer = yz_Data,                                           &
       check = yz_IntLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = 2*pi
  call AssertEqual(&
       message='vz_IntLon_xvz with constant field',                &
       answer = vz_Data,                                           &
       check = vz_IntLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = 2.0D0
  call AssertEqual(&
       message='xz_IntLat_xyz with constant field',                &
       answer = xz_Data,                                           &
       check = xz_IntLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xz_Data = 2.0D0
  call AssertEqual(&
       message='xz_IntLat_xvz with constant field',                &
       answer = xz_Data,                                           &
       check = xz_IntLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = 1/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='xy_IntRad_xyz with constant field',                &
       answer = xy_Data,                                           &
       check = xy_IntRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = 1/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='xv_IntRad_xvz with constant field',                &
       answer = xv_Data,                                           &
       check = xv_IntRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 4*pi
  call AssertEqual(&
       message='z_IntLonLat_xyz with constant field',              &
       answer = z_Data,                                            &
       check = z_IntLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  z_Data = 4*pi
  call AssertEqual(&
       message='z_IntLonLat_xvz with constant field',              &
       answer = z_Data,                                            &
       check = z_IntLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 2/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='x_IntLatRad_xyz with constant field',              &
       answer = x_Data,                                            &
       check = x_IntLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  x_Data = 2/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='x_IntLatRad_xvz with constant field',              &
       answer = x_Data,                                            &
       check = x_IntLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 2*pi/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='y_IntLonRad_xyz with constant field',              &
       answer = y_Data,                                            &
       check = y_IntLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 2*pi/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='v_IntLonRad_xvz with constant field',              &
       answer = v_Data,                                            &
       check = v_IntLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  Data = 4*pi/3*(ro**3-ri**3)
  call AssertEqual(&
       message='IntLonLatRad_xyz with constant field',             &
       answer = Data,                                              &
       check = IntLonLatRad_xyz(xyz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  Data = 4*pi/3*(ro**3-ri**3)
  call AssertEqual(&
       message='IntLonLatRad_xvz with constant field',             &
       answer = Data,                                              &
       check = IntLonLatRad_xvz(xvz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )


  !------------------ r -----------------------
  xyz_Data = xyz_Rad 
  xvz_Data = xvz_Rad 

  yz_Data = 2*pi* xyz_Rad(1,:,:)
  call AssertEqual(&
       message='yz_IntLon_xyz with r-field',                       &
       answer = yz_Data,                                           &
       check = yz_IntLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = 2*pi* xvz_Rad(1,:,:)
  call AssertEqual(&
       message='vz_IntLon_xvz with r-field',                       &
       answer = vz_Data,                                           &
       check = vz_IntLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = 2.0D0 * xyz_Data(:,1,:)
  call AssertEqual(&
       message='xz_IntLat_xyz with r-field',                       &
       answer = xz_Data,                                           &
       check = xz_IntLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xz_Data = 2.0D0 * xvz_Data(:,1,:)
  call AssertEqual(&
       message='xz_IntLat_xvz with r-field',                       &
       answer = xz_Data,                                           &
       check = xz_IntLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = 1/4.0D0*(ro**4-ri**4) 
  call AssertEqual(&
       message='xy_IntRad_xyz with r field',                       &
       answer = xy_Data,                                           &
       check = xy_IntRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = 1/4.0D0*(ro**4-ri**4) 
  call AssertEqual(&
       message='xv_IntRad_xvz with r field',                       &
       answer = xv_Data,                                           &
       check = xv_IntRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 4*pi * xyz_Data(1,1,:)
  call AssertEqual(&
       message='z_IntLonLat_xyz with r field',                     &
       answer = z_Data,                                            &
       check = z_IntLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  z_Data = 4*pi * xvz_Data(1,1,:)
  call AssertEqual(&
       message='z_IntLonLat_xvz with r field',                     &
       answer = z_Data,                                            &
       check = z_IntLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1/2.0D0*(ro**4-ri**4)
  call AssertEqual(&
       message='x_IntLatRad_xyz with r field',                     &
       answer = x_Data,                                            &
       check = x_IntLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  x_Data = 1/2.0D0*(ro**4-ri**4)
  call AssertEqual(&
       message='x_IntLatRad_xvz with r field',                     &
       answer = x_Data,                                            &
       check = x_IntLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = pi/2.0D0*(ro**4-ri**4)
  call AssertEqual(&
       message='y_IntLonRad_xyz with constant field',              &
       answer = y_Data,                                            &
       check = y_IntLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = pi/2.0D0*(ro**4-ri**4)
  call AssertEqual(&
       message='v_IntLonRad_xvz with constant field',              &
       answer = v_Data,                                            &
       check = v_IntLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  Data = pi*(ro**4-ri**4)
  call AssertEqual(&
       message='IntLonLatRad_xyz with constant field',              &
       answer = Data,                                            &
       check = IntLonLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  Data = pi*(ro**4-ri**4)
  call AssertEqual(&
       message='IntLonLatRad_xvz with constant field',              &
       answer = Data,                                            &
       check = IntLonLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  !--------- sin(phi)**2  ---------
  xyz_Data = sin(xyz_Lat)**2
  xvz_Data = sin(xvz_Lat)**2

  yz_Data = 2*pi* xyz_Data(1,:,:)
  call AssertEqual(&
       message='yz_IntLon_xyz with sin^2φ field',                 &
       answer = yz_Data,                                           &
       check = yz_IntLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = 2*pi* xvz_Data(1,:,:)
  call AssertEqual(&
       message='vz_IntLon_xvz with sin^2φ field',                 &
       answer = vz_Data,                                           &
       check = vz_IntLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = 2.0D0/3.0D0
  call AssertEqual(&
       message='xz_IntLat_xyz with sin^2φ field',                 &
       answer = xz_Data,                                           &
       check = xz_IntLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xz_Data = 2.0D0/3.0D0
  call AssertEqual(&
       message='xz_IntLat_xvz with sin^2φ field',                 &
       answer = xz_Data,                                           &
       check = xz_IntLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = 1/3.0D0*(ro**3-ri**3) * xyz_Data(:,:,1)
  call AssertEqual(&
       message='xy_IntRad_xyz with sin^2φ field',                 &
       answer = xy_Data,                                           &
       check = xy_IntRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = 1/3.0D0*(ro**3-ri**3) * xvz_Data(:,:,1)
  call AssertEqual(&
       message='xv_IntRad_xvz with sin^2φ field',                 &
       answer = xv_Data,                                           &
       check = xv_IntRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 4*pi/3.0
  call AssertEqual(&
       message='z_IntLonLat_xyz with sin^2φ field',               &
       answer = z_Data,                                            &
       check = z_IntLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  z_Data = 4*pi/3.0
  call AssertEqual(&
       message='z_IntLonLat_xvz with sin^2φ field',               &
       answer = z_Data,                                            &
       check = z_IntLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 2/9.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='x_IntLatRad_xyz with sin^2φ field',               &
       answer = x_Data,                                            &
       check = x_IntLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  x_Data = 2/9.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='x_IntLatRad_xvz with sin^2φ field',               &
       answer = x_Data,                                            &
       check = x_IntLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 2*pi/3.0D0*(ro**3-ri**3) * xyz_Data(1,:,1)
  call AssertEqual(&
       message='y_IntLonRad_xyz with sin^2φ field',               &
       answer = y_Data,                                            &
       check = y_IntLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 2*pi/3.0D0*(ro**3-ri**3) * xvz_Data(1,:,1)
  call AssertEqual(&
       message='v_IntLonRad_xvz with sin^2φ field',               &
       answer = v_Data,                                            &
       check = v_IntLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  Data = 4*pi/9*(ro**3-ri**3)
  call AssertEqual(&
       message='IntLonLatRad_xyz with constant field',             &
       answer = Data,                                              &
       check = IntLonLatRad_xyz(xyz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  Data = 4*pi/9*(ro**3-ri**3)
  call AssertEqual(&
       message='IntLonLatRad_xvz with constant field',             &
       answer = Data,                                              &
       check = IntLonLatRad_xvz(xvz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  xyz_Data = sin(xyz_Lon)**2
  xvz_Data = sin(xvz_Lon)**2

  yz_Data = pi
  call AssertEqual(&
       message='yz_IntLon_xyz with sin(lambda)**2',                &
       answer = yz_Data,                                           &
       check = yz_IntLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = pi
  call AssertEqual(&
       message='vz_IntLon_xvz with sin(lambda)**2',                &
       answer = vz_Data,                                           &
       check = vz_IntLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = 2.0D0 * xyz_Data(:,1,:)
  call AssertEqual(&
       message='xz_IntLat_xyz with sin(lambda)**2',                &
       answer = xz_Data,                                           &
       check = xz_IntLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='xz_IntLat_xvz with sin(lambda)**2',                &
       answer = xz_Data,                                           &
       check = xz_IntLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = 1/3.0D0*(ro**3-ri**3) * xyz_Data(:,:,1)
  call AssertEqual(&
       message='xy_IntRad_xyz with sin(lambda)**2',                &
       answer = xy_Data,                                           &
       check = xy_IntRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = 1/3.0D0*(ro**3-ri**3) * xvz_Data(:,:,1)
  call AssertEqual(&
       message='xv_IntRad_xvz with sin(lambda)**2',                &
       answer = xv_Data,                                           &
       check = xv_IntRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 2*pi
  call AssertEqual(&
       message='z_IntLonLat_xyz with sin(lambda)**2',              &
       answer = z_Data,                                            &
       check = z_IntLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_IntLonLat_xvz with sin(lambda)**2',              &
       answer = z_Data,                                            &
       check = z_IntLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 2.0D0/3.0D0*(ro**3-ri**3) * xyz_Data(:,1,1)
  call AssertEqual(&
       message='x_IntLatRad_xyz with sin(lambda)**2',              &
       answer = x_Data,                                            &
       check = x_IntLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_IntLatRad_xvz with sin(lambda)**2',              &
       answer = x_Data,                                            &
       check = x_IntLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = pi/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='y_IntLonRad_xyz with sin(lambda)**2',              &
       answer = y_Data,                                            &
       check = y_IntLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = pi/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='v_IntLonRad_xvz with sin(lambda)**2',              &
       answer = v_Data,                                            &
       check = v_IntLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonLatRad_xyz with sin(lambda)**2',             &
       answer = 2*pi/3*(ro**3-ri**3),                              &
       check = IntLonLatRad_xyz(xyz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLonLatRad_xvz with sin(lambda)**2',             &
       answer = 2*pi/3*(ro**3-ri**3),                              &
       check = IntLonLatRad_xvz(xvz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 積分(xy,xv) =============================
  ! 定数
  xy_Data = 1.0D0
  xv_Data = 1.0D0

  y_Data = 2*pi
  call AssertEqual(&
       message='y_IntLon_xy with constant field',                  &
       answer = y_Data,                                            &
       check = y_IntLon_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 2*pi
  call AssertEqual(&
       message='v_IntLon_xv with constant field',                  &
       answer = v_Data,                                            &
       check = v_IntLon_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 2.0D0
  call AssertEqual(&
       message='x_IntLat_xy with constant field',                  &
       answer = x_Data,                                            &
       check = x_IntLat_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_IntLat_xv with constant field',                  &
       answer = x_Data,                                            &
       check = x_IntLat_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonLat_xy with constant field',                 &
       answer = 4*pi,                                              &
       check = IntLonLat_xy(xy_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLonLat_xv with constant field',                 &
       answer = 4*pi,                                              &
       check = IntLonLat_xv(xv_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  xy_Data = sin(xy_Lon)**2
  xv_Data = sin(xv_Lon)**2

  y_Data = pi 
  call AssertEqual(&
       message='y_IntLon_xy with sin(lambda)**2',                  &
       answer = y_Data,                                            &
       check = y_IntLon_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = pi
  call AssertEqual(&
       message='v_IntLon_xv with sin(lambda)**2',                  &
       answer = v_Data,                                            &
       check = v_IntLon_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 2.0d0 * xy_Data(:,1)
  call AssertEqual(&
       message='x_IntLat_xy with sin(lambda)**2',                  &
       answer = x_Data,                                            &
       check = x_IntLat_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_IntLat_xv with sin(lambda)**2',                  &
       answer = x_Data,                                            &
       check = x_IntLat_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonLat_xy with sin(lambda)**2',                 &
       answer = 2*pi,                                              &
       check = IntLonLat_xy(xy_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLonLat_xv with sin(lambda)**2',                 &
       answer = 2*pi,                                              &
       check = IntLonLat_xv(xv_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(phi)**2 
  xy_Data = sin(xy_Lat)**2
  xv_Data = sin(xv_Lat)**2

  y_Data = 2*pi* xy_Data(1,:)
  call AssertEqual(&
       message='y_IntLon_xy with sin(phi)**2',                     &
       answer = y_Data,                                            &
       check = y_IntLon_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 2*pi* xv_Data(1,:)
  call AssertEqual(&
       message='v_IntLon_xv with sin(phi)**2',                     &
       answer = v_Data,                                            &
       check = v_IntLon_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 2.0D0/3.0D0
  call AssertEqual(&
       message='x_IntLat_xy with sin(phi)**2',                     &
       answer = x_Data,                                            &
       check = x_IntLat_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_IntLat_xv with sin(phi)**2',                     &
       answer = x_Data,                                            &
       check = x_IntLat_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonLat_xy with sin(phi)**2',                    &
       answer = 4*pi/3.0,                                          &
       check = IntLonLat_xy(xy_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLonLat_xv with sin(phi)**2',                    &
       answer = 4*pi/3.0,                                          &
       check = IntLonLat_xv(xv_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 積分(yz,vz) =============================
  ! 定数
  yz_Data = 1.0D0
  vz_Data = 1.0D0

  z_Data = 2.0D0
  call AssertEqual(&
       message='z_IntLat_yz with constant field',                  &
       answer = z_Data,                                            &
       check = z_IntLat_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_IntLat_vz with constant field',                  &
       answer = z_Data,                                            &
       check = z_IntLat_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 1/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='y_IntRad_yz with constant field',                  &
       answer = y_Data,                                            &
       check = y_IntRad_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 1/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='v_IntRad_vz with constant field',                  &
       answer = v_Data,                                            &
       check = v_IntRad_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLatRad_yz with constant field',                 &
       answer = 2/3.0D0*(ro**3-ri**3),                             &
       check = IntLatRad_yz(yz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLatRad_vz with constant field',                 &
       answer = 2/3.0D0*(ro**3-ri**3),                             &
       check = IntLatRad_vz(vz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! r^2 
  yz_Data = xyz_Rad(0,:,:)**2
  vz_Data = xvz_Rad(0,:,:)**2

  z_Data = 2.0D0 * yz_Data(1,:)
  call AssertEqual(&
       message='z_IntLat_yz with r^2',                             &
       answer = z_Data,                                            &
       check = z_IntLat_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_IntLat_vz with r^2',                             &
       answer = z_Data,                                            &
       check = z_IntLat_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 1/5.0D0*(ro**5-ri**5)
  call AssertEqual(&
       message='y_IntRad_yz with r^2',                             &
       answer = y_Data,                                            &
       check = y_IntRad_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 1/5.0D0*(ro**5-ri**5)
  call AssertEqual(&
       message='v_IntRad_vz with r^2',                             &
       answer = v_Data,                                            &
       check = v_IntRad_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLatRad_yz with r^2',                            &
       answer = 2/5.0D0*(ro**5-ri**5),                             &
       check = IntLatRad_yz(yz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLatRad_vz with r^2',                            &
       answer = 2/5.0D0*(ro**5-ri**5),                             &
       check = IntLatRad_vz(vz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(phi)**2 
  yz_Data = sin(xyz_Lat(0,:,:))**2
  vz_Data = sin(xvz_Lat(0,:,:))**2

  z_Data = 2.0D0/3.0D0
  call AssertEqual(&
       message='z_IntLat_yz with sin(phi)**2',                     &
       answer = z_Data,                                            &
       check = z_IntLat_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_IntLat_vz with sin(phi)**2',                     &
       answer = z_Data,                                            &
       check = z_IntLat_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 1/3.0D0*(ro**3-ri**3) * yz_Data(:,1)
  call AssertEqual(&
       message='y_IntRad_yz with sin(phi)**2',                     &
       answer = y_Data,                                            &
       check = y_IntRad_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 1/3.0D0*(ro**3-ri**3) * vz_Data(:,1)
  call AssertEqual(&
       message='v_IntRad_vz with sin(phi)**2',                     &
       answer = v_Data,                                            &
       check = v_IntRad_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLatRad_yz with sin(phi)**2',                    &
       answer = 2/9.0D0*(ro**3-ri**3),                             &
       check = IntLatRad_yz(yz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLatRad_vz with sin(phi)**2',                    &
       answer = 2/9.0D0*(ro**3-ri**3),                             &
       check = IntLatRad_vz(vz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 積分(xz) =============================
  ! 定数
  xz_Data = 1.0D0

  z_Data = 2*pi
  call AssertEqual(&
       message='z_IntLon_xz with constant field',                  &
       answer = z_Data,                                            &
       check = z_IntLon_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1/3.0D0*(ro**3-ri**3)
  call AssertEqual(&
       message='x_IntRad_xz with constant field',                  &
       answer = x_Data,                                            &
       check = x_IntRad_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonRad_xz with constant field',                 &
       answer = 2*pi/3.0D0*(ro**3-ri**3),                          &
       check = IntLonRad_xz(xz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  xz_Data = sin(xyz_Lon(:,1,:))**2

  z_Data = pi
  call AssertEqual(&
       message='z_IntLon_xz with sin(lambda)**2',                  &
       answer = z_Data,                                            &
       check = z_IntLon_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1/3.0D0*(ro**3-ri**3) * xz_Data(:,1)
  call AssertEqual(&
       message='x_IntRad_xz with sin(lambda)**2',                  &
       answer = x_Data,                                            &
       check = x_IntRad_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonRad_xz with sin(lambda)**2',                 &
       answer = pi/3.0D0*(ro**3-ri**3) ,                           &
       check = IntLonRad_xz(xz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! r^2 
  xz_Data = spread(z_Rad**2,1,im)

  z_Data = 2*pi* z_Rad**2
  call AssertEqual(&
       message='z_IntLon_xz with r^2',                             &
       answer = z_Data,                                            &
       check = z_IntLon_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1/5.0D0*(ro**5-ri**5)
  call AssertEqual(&
       message='x_IntRad_xz with r^2',                             &
       answer = x_Data,                                            &
       check = x_IntRad_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='IntLonRad_xz with r^2',                            &
       answer = 2*pi/5.0D0*(ro**5-ri**5),                          &
       check = IntLonRad_xz(xz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 積分(x) =============================
  ! 定数
  x_Data = 1.0D0

  call AssertEqual(&
       message='IntLon_x with constant field',                     &
       answer = 2*pi,                                              &
       check = IntLon_x(x_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  x_Data = sin(x_Lon)**2

  call AssertEqual(&
       message='IntLon_x with sin(lambda)**2',                     &
       answer = pi,                                                &
       check = IntLon_x(x_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 積分(y,v) =============================
  ! 定数
  y_Data = 1.0D0
  v_Data = 1.0D0

  call AssertEqual(&
       message='IntLat_y with constant field',                     &
       answer = 2.0D0,                                             &
       check = IntLat_y(y_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLat_v with constant field',                     &
       answer = 2.0D0,                                             &
       check = IntLat_v(v_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(phi)**2 
  y_Data = sin(y_Lat)**2
  v_Data = sin(v_Lat)**2

  call AssertEqual(&
       message='IntLat_y with sin(phi)**2',                        &
       answer = 2.0D0/3.0D0,                                       &
       check = IntLat_y(y_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='IntLat_v with sin(phi)**2',                        &
       answer = 2.0D0/3.0D0,                                       &
       check = IntLat_v(v_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 積分(z) =============================
  ! 定数
  z_Data = 1.0D0

  call AssertEqual(&
       message='IntRad_r with constant field',                     &
       answer = 1/3.0D0*(ro**3-ri**3),                             &
       check = IntRad_z(z_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! r^2 
  z_Data = z_Rad**2

  call AssertEqual(&
       message='IntRad_r with r^2',                                &
       answer = 1/5.0D0*(ro**5-ri**5),                             &
       check = IntRad_z(z_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

!============================ 平均(xyz,xvz) ==============================

 !---------- 定数 ----------
  xyz_Data = 1.0D0
  xvz_Data = 1.0D0

  yz_Data = 1.0D0
  call AssertEqual(&
       message='yz_AvrLon_xyz with constant field',                &
       answer = yz_Data,                                           &
       check = yz_AvrLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = 1.0D0
  call AssertEqual(&
       message='vz_AvrLon_xvz with constant field',                &
       answer = vz_Data,                                           &
       check = vz_AvrLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = 1.0D0
  call AssertEqual(&
       message='xz_AvrLat_xyz with constant field',                &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xz_Data = 1.0D0
  call AssertEqual(&
       message='xz_AvrLat_xvz with constant field',                &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = 1.0D0
  call AssertEqual(&
       message='xy_AvrRad_xyz with constant field',                &
       answer = xy_Data,                                           &
       check = xy_AvrRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = 1.0D0
  call AssertEqual(&
       message='xv_AvrRad_xvz with constant field',                &
       answer = xv_Data,                                           &
       check = xv_AvrRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 1.0D0
  call AssertEqual(&
       message='z_AvrLonLat_xyz with constant field',              &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  z_Data = 1.0D0
  call AssertEqual(&
       message='z_AvrLonLat_xvz with constant field',              &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1.0D0
  call AssertEqual(&
       message='x_AvrLatRad_xyz with constant field',              &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  x_Data = 1.0D0
  call AssertEqual(&
       message='x_AvrLatRad_xvz with constant field',              &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 1.0D0
  call AssertEqual(&
       message='y_AvrLonRad_xyz with constant field',              &
       answer = y_Data,                                            &
       check = y_AvrLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 1.0D0
  call AssertEqual(&
       message='v_AvrLonRad_xvz with constant field',              &
       answer = v_Data,                                            &
       check = v_AvrLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  Data = 1.0D0
  call AssertEqual(&
       message='AvrLonLatRad_xyz with constant field',             &
       answer = Data,                                              &
       check = AvrLonLatRad_xyz(xyz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  Data = 1.0D0
  call AssertEqual(&
       message='AvrLonLatRad_xvz with constant field',             &
       answer = Data,                                              &
       check = AvrLonLatRad_xvz(xvz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  !------------------ r -----------------------
  xyz_Data = xyz_Rad 
  xvz_Data = xvz_Rad 

  yz_Data = xyz_Rad(1,:,:)
  call AssertEqual(&
       message='yz_AvrLon_xyz with r-field',                &
       answer = yz_Data,                                           &
       check = yz_AvrLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = xvz_Rad(1,:,:)
  call AssertEqual(&
       message='vz_AvrLon_xvz with r-field',                &
       answer = vz_Data,                                           &
       check = vz_AvrLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = xyz_Data(:,1,:)
  call AssertEqual(&
       message='xz_AvrLat_xyz with r-field',                &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xz_Data = xvz_Data(:,1,:)
  call AssertEqual(&
       message='xz_AvrLat_xvz with r-field',                &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = 1.0D0/4.0D0*(ro**4-ri**4)/(1/3.0D0*(ro**3-ri**3))
  call AssertEqual(&
       message='xy_AvrRad_xyz with r field',                &
       answer = xy_Data,                                           &
       check = xy_AvrRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = 1.0D0/4.0D0*(ro**4-ri**4)/(1/3.0D0*(ro**3-ri**3))
  call AssertEqual(&
       message='xv_AvrRad_xvz with r field',                &
       answer = xv_Data,                                           &
       check = xv_AvrRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = xyz_Data(1,1,:)
  call AssertEqual(&
       message='z_AvrLonLat_xyz with r field',                     &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  z_Data = xvz_Data(1,1,:)
  call AssertEqual(&
       message='z_AvrLonLat_xvz with r field',                     &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1/2.0D0*(ro**4-ri**4)/(2/3.0D0*(ro**3-ri**3))
  call AssertEqual(&
       message='x_AvrLatRad_xyz with r field',                     &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  x_Data = 1/2.0D0*(ro**4-ri**4)/(2/3.0D0*(ro**3-ri**3))
  call AssertEqual(&
       message='x_AvrLatRad_xvz with r field',                     &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = pi/2.0D0*(ro**4-ri**4)/(2*pi/3.0D0*(ro**3-ri**3))
  call AssertEqual(&
       message='y_AvrLonRad_xyz with constant field',              &
       answer = y_Data,                                            &
       check = y_AvrLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = pi/2.0D0*(ro**4-ri**4)/(2*pi/3.0D0*(ro**3-ri**3))
  call AssertEqual(&
       message='v_AvrLonRad_xvz with constant field',              &
       answer = v_Data,                                            &
       check = v_AvrLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  Data = pi*(ro**4-ri**4)/(4*pi/3*(ro**3-ri**3))
  call AssertEqual(&
       message='AvrLonLatRad_xyz with constant field',              &
       answer = Data,                                            &
       check = AvrLonLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  Data = pi*(ro**4-ri**4)/(4*pi/3*(ro**3-ri**3))
  call AssertEqual(&
       message='AvrLonLatRad_xvz with constant field',              &
       answer = Data,                                            &
       check = AvrLonLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  !--------- sin(phi)**2  ---------
  xyz_Data = sin(xyz_Lat)**2
  xvz_Data = sin(xvz_Lat)**2

  yz_Data = xyz_Data(1,:,:)
  call AssertEqual(&
       message='yz_AvrLon_xyz with sin^2φ field',                 &
       answer = yz_Data,                                           &
       check = yz_AvrLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = xvz_Data(1,:,:)
  call AssertEqual(&
       message='vz_AvrLon_xvz with sin^2φ field',                 &
       answer = vz_Data,                                           &
       check = vz_AvrLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='xz_AvrLat_xyz with sin^2φ field',                 &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xz_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='xz_AvrLat_xvz with sin^2φ field',                 &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = xyz_Data(:,:,1)
  call AssertEqual(&
       message='xy_AvrRad_xyz with sin^2φ field',                 &
       answer = xy_Data,                                           &
       check = xy_AvrRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = xvz_Data(:,:,1)
  call AssertEqual(&
       message='xv_AvrRad_xvz with sin^2φ field',                 &
       answer = xv_Data,                                           &
       check = xv_AvrRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='z_AvrLonLat_xyz with sin^2φ field',               &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  z_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='z_AvrLonLat_xvz with sin^2φ field',               &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='x_AvrLatRad_xyz with sin^2φ field',               &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  x_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='x_AvrLatRad_xvz with sin^2φ field',               &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = xyz_Data(1,:,1)
  call AssertEqual(&
       message='y_AvrLonRad_xyz with sin^2φ field',               &
       answer = y_Data,                                            &
       check = y_AvrLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = xvz_Data(1,:,1)
  call AssertEqual(&
       message='v_AvrLonRad_xvz with sin^2φ field',               &
       answer = v_Data,                                            &
       check = v_AvrLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  Data = 1.0D0/3D0
  call AssertEqual(&
       message='AvrLonLatRad_xyz with constant field',             &
       answer = Data,                                              &
       check = AvrLonLatRad_xyz(xyz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  Data = 1.0D0/3D0
  call AssertEqual(&
       message='AvrLonLatRad_xvz with constant field',             &
       answer = Data,                                              &
       check = AvrLonLatRad_xvz(xvz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  xyz_Data = sin(xyz_Lon)**2
  xvz_Data = sin(xvz_Lon)**2

  yz_Data = 0.5D0
  call AssertEqual(&
       message='yz_AvrLon_xyz with sin(lambda)**2',                &
       answer = yz_Data,                                           &
       check = yz_AvrLon_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  vz_Data = 0.5D0
  call AssertEqual(&
       message='vz_AvrLon_xvz with sin(lambda)**2',                &
       answer = vz_Data,                                           &
       check = vz_AvrLon_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xz_Data = xyz_Data(:,1,:)
  call AssertEqual(&
       message='xz_AvrLat_xyz with sin(lambda)**2',                &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='xz_AvrLat_xvz with sin(lambda)**2',                &
       answer = xz_Data,                                           &
       check = xz_AvrLat_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  xy_Data = xyz_Data(:,:,1)
  call AssertEqual(&
       message='xy_AvrRad_xyz with sin(lambda)**2',                &
       answer = xy_Data,                                           &
       check = xy_AvrRad_xyz(xyz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  xv_Data = xvz_Data(:,:,1)
  call AssertEqual(&
       message='xv_AvrRad_xvz with sin(lambda)**2',                &
       answer = xv_Data,                                           &
       check = xv_AvrRad_xvz(xvz_Data),                            &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  z_Data = 0.5D0
  call AssertEqual(&
       message='z_AvrLonLat_xyz with sin(lambda)**2',              &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_AvrLonLat_xvz with sin(lambda)**2',              &
       answer = z_Data,                                            &
       check = z_AvrLonLat_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = xyz_Data(:,1,1)
  call AssertEqual(&
       message='x_AvrLatRad_xyz with sin(lambda)**2',              &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_AvrLatRad_xvz with sin(lambda)**2',              &
       answer = x_Data,                                            &
       check = x_AvrLatRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 0.5D0
  call AssertEqual(&
       message='y_AvrLonRad_xyz with sin(lambda)**2',              &
       answer = y_Data,                                            &
       check = y_AvrLonRad_xyz(xyz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 0.5D0
  call AssertEqual(&
       message='v_AvrLonRad_xvz with sin(lambda)**2',              &
       answer = v_Data,                                            &
       check = v_AvrLonRad_xvz(xvz_Data),                          &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonLatRad_xyz with sin(lambda)**2',             &
       answer = 0.5D0,                                             &
       check = AvrLonLatRad_xyz(xyz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLonLatRad_xvz with sin(lambda)**2',             &
       answer = 0.5D0,                                             &
       check = AvrLonLatRad_xvz(xvz_Data),                         &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 平均(xy,xv) =============================
  ! 定数
  xy_Data = 1.0D0
  xv_Data = 1.0D0

  y_Data = 1.0D0
  call AssertEqual(&
       message='y_AvrLon_xy with constant field',                  &
       answer = y_Data,                                            &
       check = y_AvrLon_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 1.0D0
  call AssertEqual(&
       message='v_AvrLon_xv with constant field',                  &
       answer = v_Data,                                            &
       check = v_AvrLon_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1.0D0
  call AssertEqual(&
       message='x_AvrLat_xy with constant field',                  &
       answer = x_Data,                                            &
       check = x_AvrLat_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_AvrLat_xv with constant field',                  &
       answer = x_Data,                                            &
       check = x_AvrLat_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonLat_xy with constant field',                 &
       answer = 1.0D0,                                             &
       check = AvrLonLat_xy(xy_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLonLat_xv with constant field',                 &
       answer = 1.0D0,                                             &
       check = AvrLonLat_xv(xv_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  xy_Data = sin(xy_Lon)**2
  xv_Data = sin(xv_Lon)**2

  y_Data = 0.5D0
  call AssertEqual(&
       message='y_AvrLon_xy with sin(lambda)**2',                  &
       answer = y_Data,                                            &
       check = y_AvrLon_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 0.5D0
  call AssertEqual(&
       message='v_AvrLon_xv with sin(lambda)**2',                  &
       answer = v_Data,                                            &
       check = v_AvrLon_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = xy_Data(:,1)
  call AssertEqual(&
       message='x_AvrLat_xy with sin(lambda)**2',                  &
       answer = x_Data,                                            &
       check = x_AvrLat_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_AvrLat_xv with sin(lambda)**2',                  &
       answer = x_Data,                                            &
       check = x_AvrLat_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonLat_xy with sin(lambda)**2',                 &
       answer = 0.5D0,                                             &
       check = AvrLonLat_xy(xy_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLonLat_xv with sin(lambda)**2',                 &
       answer = 0.5D0,                                             &
       check = AvrLonLat_xv(xv_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(phi)**2 
  xy_Data = sin(xy_Lat)**2
  xv_Data = sin(xv_Lat)**2

  y_Data = xy_Data(1,:)
  call AssertEqual(&
       message='y_AvrLon_xy with sin(phi)**2',                     &
       answer = y_Data,                                            &
       check = y_AvrLon_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = xv_Data(1,:)
  call AssertEqual(&
       message='v_AvrLon_xv with sin(phi)**2',                     &
       answer = v_Data,                                            &
       check = v_AvrLon_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='x_AvrLat_xy with sin(phi)**2',                     &
       answer = x_Data,                                            &
       check = x_AvrLat_xy(xy_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='x_AvrLat_xv with sin(phi)**2',                     &
       answer = x_Data,                                            &
       check = x_AvrLat_xv(xv_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonLat_xy with sin(phi)**2',                    &
       answer = 1.0D0/3.0D0,                                       &
       check = AvrLonLat_xy(xy_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLonLat_xv with sin(phi)**2',                    &
       answer = 1.0D0/3.0D0,                                       &
       check = AvrLonLat_xv(xv_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 平均(yz,vz) =============================
  ! 定数
  yz_Data = 1.0D0
  vz_Data = 1.0D0

  z_Data = 1.0D0
  call AssertEqual(&
       message='z_AvrLat_yz with constant field',                  &
       answer = z_Data,                                            &
       check = z_AvrLat_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_AvrLat_vz with constant field',                  &
       answer = z_Data,                                            &
       check = z_AvrLat_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 1.0D0
  call AssertEqual(&
       message='y_AvrRad_yz with constant field',                  &
       answer = y_Data,                                            &
       check = y_AvrRad_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 1.0D0
  call AssertEqual(&
       message='v_AvrRad_vz with constant field',                  &
       answer = v_Data,                                            &
       check = v_AvrRad_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLatRad_yz with constant field',                 &
       answer = 1.0D0,                                             &
       check = AvrLatRad_yz(yz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLatRad_vz with constant field',                 &
       answer = 1.0D0,                                             &
       check = AvrLatRad_vz(vz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! r^2 
  yz_Data = xyz_Rad(0,:,:)**2
  vz_Data = xvz_Rad(0,:,:)**2

  z_Data = yz_Data(1,:)
  call AssertEqual(&
       message='z_AvrLat_yz with r^2',                             &
       answer = z_Data,                                            &
       check = z_AvrLat_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_AvrLat_vz with r^2',                             &
       answer = z_Data,                                            &
       check = z_AvrLat_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3)
  call AssertEqual(&
       message='y_AvrRad_yz with r^2',                             &
       answer = y_Data,                                            &
       check = y_AvrRad_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3)
  call AssertEqual(&
       message='v_AvrRad_vz with r^2',                             &
       answer = v_Data,                                            &
       check = v_AvrRad_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLatRad_yz with r^2',                            &
       answer = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3),           &
       check = AvrLatRad_yz(yz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLatRad_vz with r^2',                            &
       answer = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3),           &
       check = AvrLatRad_vz(vz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(phi)**2 
  yz_Data = sin(xyz_Lat(0,:,:))**2
  vz_Data = sin(xvz_Lat(0,:,:))**2

  z_Data = 1.0D0/3.0D0
  call AssertEqual(&
       message='z_AvrLat_yz with sin(phi)**2',                     &
       answer = z_Data,                                            &
       check = z_AvrLat_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='z_AvrLat_vz with sin(phi)**2',                     &
       answer = z_Data,                                            &
       check = z_AvrLat_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  y_Data = yz_Data(:,1)
  call AssertEqual(&
       message='y_AvrRad_yz with sin(phi)**2',                     &
       answer = y_Data,                                            &
       check = y_AvrRad_yz(yz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  v_Data = vz_Data(:,1)
  call AssertEqual(&
       message='v_AvrRad_vz with sin(phi)**2',                     &
       answer = v_Data,                                            &
       check = v_AvrRad_vz(vz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLatRad_yz with sin(phi)**2',                    &
       answer = 1.0D0/3.0D0,                                       &
       check = AvrLatRad_yz(yz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLatRad_vz with sin(phi)**2',                    &
       answer = 1.0D0/3.0D0,                                       &
       check = AvrLatRad_vz(vz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 平均(xz) =============================
  ! 定数
  xz_Data = 1.0D0

  z_Data = 1.0D0
  call AssertEqual(&
       message='z_AvrLon_xz with constant field',                  &
       answer = z_Data,                                            &
       check = z_AvrLon_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 1.0D0
  call AssertEqual(&
       message='x_AvrRad_xz with constant field',                  &
       answer = x_Data,                                            &
       check = x_AvrRad_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonRad_xz with constant field',                 &
       answer = 1.0D0,                                             &
       check = AvrLonRad_xz(xz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  xz_Data = sin(xyz_Lon(:,1,:))**2

  z_Data = 0.5D0
  call AssertEqual(&
       message='z_AvrLon_xz with sin(lambda)**2',                  &
       answer = z_Data,                                            &
       check = z_AvrLon_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = xz_Data(:,1)
  call AssertEqual(&
       message='x_AvrRad_xz with sin(lambda)**2',                  &
       answer = x_Data,                                            &
       check = x_AvrRad_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonRad_xz with sin(lambda)**2',                 &
       answer = 0.5D0,                                             &
       check = AvrLonRad_xz(xz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! r^2 
  xz_Data = spread(z_Rad**2,1,im)

  z_Data = z_Rad**2
  call AssertEqual(&
       message='z_AvrLon_xz with r^2',                             &
       answer = z_Data,                                            &
       check = z_AvrLon_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  x_Data = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3)
  call AssertEqual(&
       message='x_AvrRad_xz with r^2',                             &
       answer = x_Data,                                            &
       check = x_AvrRad_xz(xz_Data),                               &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call AssertEqual(&
       message='AvrLonRad_xz with r^2',                            &
       answer = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3),           &
       check = AvrLonRad_xz(xz_Data),                              &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 平均(x) =============================
  ! 定数
  x_Data = 1.0D0

  call AssertEqual(&
       message='AvrLon_x with constant field',                     &
       answer = 1.0D0,                                             &
       check = AvrLon_x(x_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(lambda)**2
  x_Data = sin(x_Lon)**2

  call AssertEqual(&
       message='AvrLon_x with sin(lambda)**2',                     &
       answer = 0.5D0,                                             &
       check = AvrLon_x(x_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 平均(y,v) =============================
  ! 定数
  y_Data = 1.0D0
  v_Data = 1.0D0

  xz_Data = 1.0D0
  call AssertEqual(&
       message='AvrLat_y with constant field',                     &
       answer = 1.0D0,                                             &
       check = AvrLat_y(y_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLat_v with constant field',                     &
       answer = 1.0D0,                                             &
       check = AvrLat_v(v_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! sin(phi)**2 
  y_Data = sin(y_Lat)**2
  v_Data = sin(v_Lat)**2

  call AssertEqual(&
       message='AvrLat_y with sin(phi)**2',                        &
       answer = 1.0D0/3.0D0,                                       &
       check = AvrLat_y(y_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )
  call AssertEqual(&
       message='AvrLat_v with sin(phi)**2',                        &
       answer = 1.0D0/3.0D0,                                       &
       check = AvrLat_v(v_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

 !============================ 平均(r) =============================
  ! 定数
  z_Data = 1.0D0

  call AssertEqual(&
       message='AvrRad_r with constant field',                     &
       answer = 1.0D0,                                             &
       check = AvrRad_z(z_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  ! r^2 
  z_Data = z_Rad**2

  call AssertEqual(&
       message='AvrRad_r with r^2',                                &
       answer = 3.0D0/5.0D0*(ro**5-ri**5)/(ro**3-ri**3),           &
       check = AvrRad_z(z_Data),                                   &
       significant_digits = check_digits, ignore_digits = ignore   &
       )

  call MessageNotify('M','wtq_mpi_module_sjpack_integral_wt_test', &
       'wtq_mpi_module_sjpack wt-integration/averaging function tests succeeded!')

 !------ MPIの終了 ------

  call MPI_FINALIZE(IERR)

end program wtq_mpi_sjpack_integral_wt
