!== Sample program for gtool_history/gtool5 (MPI version)
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: histget_mpi.f90,v 1.4 2009-03-02 05:55:16 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
! License::   See COPYRIGHT[link:../COPYRIGHT]
!

program histget
  ! histget_mpi.f90 - Sample program for gtool_history/gtool5 (MPI).
  !                   Test Program for "HistoryGet".
  !

  use dc_trace,   only: SetDebug, DataDump
  use dc_message, only: MessageNotify
  use dc_types,   only: STRING, DP
  use dc_string,  only: StoA, toChar
  use dc_test, only: AssertEqual
  use gtool_history
  use mpi
  implicit none
  integer   :: err_mpi, myrank_mpi, nprocs_mpi
  integer   :: i,j,k,l                        ! ä½œæ¥å¤‰æ•°
  integer   :: nx, ny, nz                     ! ã‚°ãƒªãƒƒãƒ‰æ•°
  integer   :: time_period=3                  ! æ™‚é–“
  real,     allocatable :: x(:)               ! xåº§æ¨™å¤‰æ•°
  real(DP), allocatable :: y(:)               ! yåº§æ¨™å¤‰æ•°
  real(DP), allocatable :: z(:)               ! zåº§æ¨™å¤‰æ•°

  real                  :: u           ! å‡ºåŠ›å…¼å…¥åŠ›ç”¨ç„¡æ¬¡å…ƒé…åˆ—
  real(DP), allocatable :: v(:)        ! å‡ºåŠ›å…¼å…¥åŠ›ç”¨ 1 æ¬¡å…ƒé…åˆ—
  real(DP), allocatable :: v2(:)       ! å‡ºåŠ›å…¼å…¥åŠ›ç”¨ 1 æ¬¡å…ƒé…åˆ—ãã®2
  integer , allocatable :: w(:,:)      ! å‡ºåŠ›å…¼å…¥åŠ›ç”¨ 2 æ¬¡å…ƒé…åˆ—
  real(DP), allocatable :: q(:,:,:)    ! å‡ºåŠ›å…¼å…¥åŠ›ç”¨ 3 æ¬¡å…ƒé…åˆ—

  real(DP), allocatable:: qa(:,:,:)  ! å…¥åŠ›ç”¨ 3 æ¬¡å…ƒé…åˆ—

  real,     pointer   :: up       =>null() ! å…¥åŠ›ç”¨ç„¡æ¬¡å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿
  real(DP), pointer   :: vp(:)    =>null() ! å…¥åŠ›ç”¨ 1 æ¬¡å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿
  integer,  pointer   :: wp(:,:)  =>null() ! å…¥åŠ›ç”¨ 2 æ¬¡å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿
  real(DP), pointer   :: qp(:,:,:)=>null() ! å…¥åŠ›ç”¨ 3 æ¬¡å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿

  real,     pointer   :: xp(:) =>null()    ! å…¥åŠ›ç”¨ xåº§æ¨™å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿
  real(DP), pointer   :: yp(:) =>null()    ! å…¥åŠ›ç”¨ yåº§æ¨™å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿
  real(DP), pointer   :: zp(:) =>null()    ! å…¥åŠ›ç”¨ zåº§æ¨™å…ƒé…åˆ—ãƒã‚¤ãƒ³ã‚¿

  real(DP), pointer   :: vp_range     =>null() ! range ã§ã®å…¥åŠ›ãƒ†ã‚¹ãƒˆç”¨
  real(DP), pointer   :: qp_range(:,:)=>null() ! range ã§ã®å…¥åŠ›ãƒ†ã‚¹ãƒˆç”¨

  real(DP):: rettime
  logical:: texist
  logical:: err
  character(STRING), parameter  :: subname = 'histget_mpi'
continue

  !-----------------------------------------------------------------
  !  MPI åˆæœŸè¨å®š
  !-----------------------------------------------------------------
  call MPI_Init(err_mpi)
  call MPI_Comm_Rank(MPI_COMM_WORLD, myrank_mpi, err_mpi)
  call MPI_Comm_Size(MPI_COMM_WORLD, nprocs_mpi, err_mpi)

  if ( nprocs_mpi /= 4 ) then
    call MessageNotify( 'E', 'histget_mpi', 'Test must be done with 4 node')
  end if

  call SetDebug

  !-------------------------------------------------------------------
  !  å‰²ä»˜ã¨åˆæœŸå€¤è¨å®š
  !-------------------------------------------------------------------
  nx = 3 ; ny = 2 ; nz = 2
  allocate( x(nx), y(ny), z(nz), v(nx), v2(nz), w(nx,ny), q(nx,ny,nz) )

  x(:) = (/( 1.0*(i-1), i=1, nx )/)
  select case( myrank_mpi )
  case(0)
    y(:) = (/  0.0, 10.0 /) ; z(:) = (/   0.0, 100.0 /)
  case(1)
    y(:) = (/  0.0, 10.0 /) ; z(:) = (/ 200.0, 300.0 /)
  case(2)
    y(:) = (/ 20.0, 30.0 /) ; z(:) = (/   0.0, 100.0 /)
  case(3)
    y(:) = (/ 20.0, 30.0 /) ; z(:) = (/ 200.0, 300.0 /)
  case default
    call MessageNotify( 'E', 'histget_mpi', 'Test must be done with 4 node')
  end select

  !-------------------------------------------------------------------
  !  ã‚¨ãƒ©ãƒ¼ãƒ•ãƒ©ã‚°ã®ãƒã‚§ãƒƒã‚¯
  !-------------------------------------------------------------------
  err = .false.
  call HistoryGet('xhistget_mpi/xhistget_non.nc', 'v', v, err = err)
  call AssertEqual('err flag test 1', answer = .true., check = err)

  !-------------------------------------------------------------------
  !  ã¾ãšã¯å…¥åŠ›ç”¨ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ä½œæˆ
  !-------------------------------------------------------------------

  call HistoryCreate(file='xhistget_mpi/xhistget1.nc', &
    & title='gtool_history HistoryGet test 1', &
    & source='gtool5/Fortran library test kit', &
    & institution='GFD Dennou Club', &
    & dims=StoA('x','y','z','t'), &
    & dimsizes=(/nx,ny,nz,0/), &
    & longnames=StoA('X-coordinate','Y-coordinate', 'Z-coordinate','time'), &
    & units=StoA('m','m','m','s'), &
    & origin=0.0, interval=0.2, &
    & xtypes=StoA('real','double','double','real'), &
    & flag_mpi_split=.true. )

  call HistoryPut('x',x)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('y',y)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('z',z)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›

  call HistoryAddVariable('scalar', dims=(/''/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('u', dims=(/'t'/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('v', dims=(/'x','t'/), &
    & longname='1 Dimensional any quantity', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('v2', dims=(/'z','t'/), &
    & longname='1 Dimensional any quantity II', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('w', dims=(/'x','y','t'/), &
    & longname='2 Dimensional any quantity', &
    & units='2-dimensional any unit', xtype='int')
  call HistoryAddVariable('q', dims=(/'x','y','z','t'/), &
    & longname='3 Dimensional any quantity', &
    & units='3-dimensional any unit', xtype='double')

  call HistoryPut('scalar', 123.0)
  do, l = 1, time_period
    u = real(l)*0.100000001
    do i = 1, nx
      v(i) = dble(l)*0.100000001d0+dble(i)*10.0000001d0
      do j = 1, ny
        w(i,j) = l + i * 10 + j * 1000
        do k = 1, nz
          q(i,j,k) = dble(l)*0.100000001d0     &
            & + dble(i)*10.0000001d0  &
            & + dble(j)*1000.00001d0  &
            & + dble(k)*100000.001d0

          v2(k) = dble(k)*100000.001d0 + dble(l)
        enddo
      enddo
    enddo
    call HistoryPut('t', real(l)*0.2)
    call HistoryPut('u', u)
    call HistoryPut('v', v)
    call HistoryPut('v2', v2)
    call HistoryPut('w', w)
    call HistoryPut('q', q)

  enddo

  call DataDump('v', v, strlen=10)
  call DataDump('w', dble(w), strlen=60)
  call DataDump('q(1,1,', q(1,1,:))

  call HistoryClose

  !-------------------------------------------------------------------
  !  å›ºå®šé•·é…åˆ—ã«ã‚ˆã‚‹å…¥åŠ›ãƒ†ã‚¹ãƒˆ (è‰²ã€…ãªä½œæ³•ã§å…¥åŠ›)
  !-------------------------------------------------------------------

  call MessageNotify('M', subname, 'Getting by Fixed-Length Array.')

  call HistoryCreate(file='xhistget_mpi/xhistget2.nc', &
    & title='gtool_history HistoryGet test 1', &
    & source='gtool5/Fortran library test kit', &
    & institution='GFD Dennou Club', &
    & dims=(/'x','y','z','t'/), &
    & dimsizes=(/nx,ny,nz,0/), &
    & longnames=(/'X-coordinate','Y-coordinate', &
    &  'Z-coordinate','time        '/), &
    & units=(/'m','m','m','s'/), &
    & origin=0.0, interval=0.2, &
    & xtypes=(/'real  ','double','double','real  '/), &
    & flag_mpi_split=.true. )

  call HistoryPut('x',x)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('y',y)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('z',z)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›

  call HistoryAddVariable('scalar', dims=(/''/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('u', dims=(/'t'/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('v', dims=(/'x','t'/), &
    & longname='1 Dimensional any quantity', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('v2', dims=(/'z','t'/), &
    & longname='1 Dimensional any quantity II', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('w', dims=(/'x','y','t'/), &
    & longname='2 Dimensional any quantity', &
    & units='2-dimensional any unit', xtype='int')
  call HistoryAddVariable('q', dims=(/'x','y','z','t'/), &
    & longname='3 Dimensional any quantity', &
    & units='3-dimensional any unit', xtype='double')

  call HistoryGet(file='xhistget_mpi/xhistget1.nc', varname='scalar', &
    & array=u, flag_mpi_split=.true. )
  call HistoryPut('scalar', u)
  do, l = 1, time_period - 1
    call HistoryPut('t', real(l)*0.2)
    call HistoryGet(file='xhistget_mpi/xhistget1.nc', varname='u', &
      &          array=u, time=real(l)*0.2, flag_mpi_split=.true.)
    call HistoryPut('u', u)
    call HistoryGet('xhistget_mpi/xhistget1.nc', 'v', v, dble(l)*0.2_DP, flag_mpi_split=.true.)
    call HistoryPut('v', v)
    call HistoryGet('xhistget_mpi/xhistget1.nc', 'v2', v2, range='t=^'//toChar(l), flag_mpi_split=.true.)
    call HistoryPut('v2', v2)
    call HistoryGet('xhistget_mpi/xhistget1.nc', 'w', w, time=real(l)*0.2, flag_mpi_split=.true.)
    call HistoryPut('w', w)
    call HistoryGet('xhistget_mpi/xhistget1.nc', 'q', q, 't=^'//toChar(l), flag_mpi_split=.true.)
    call HistoryPut('q', q)
  enddo

  !---------------------------
  !  æ™‚é–“ã®è‡ªå‹•åˆ¤åˆ¥ã®ãƒ†ã‚¹ãƒˆ
  l = time_period
  call HistoryPut('t', real(l)*0.2)
  call HistoryGet(file='xhistget_mpi/xhistget1.nc', varname='u', array=u, flag_mpi_split=.true.)
  call HistoryPut('u', u)
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'v', v, range='', flag_mpi_split=.true.)
  call HistoryPut('v', v)
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'v2', v2, time=real(l)*0.2, flag_mpi_split=.true.)
  call HistoryPut('v2', v2)
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'w', w, flag_mpi_split=.true.)
  call HistoryPut('w', w)
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'q', q, 't=^'//toChar(l), flag_mpi_split=.true.)
  call HistoryPut('q', q)

  call HistoryClose

  !---------------------------
  !  é…åˆ—ã‚µã‚¤ã‚ºãŒç•°ãªã‚‹å ´åˆã®å‡¦ç†
  allocate( qa (nx+1,ny+1,nz+1) )

  err = .false.
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'v', qa, &
    & quiet = .true., err = err, flag_mpi_split=.true. )
  call AssertEqual('rank consistency test 1', answer = .true., check = err)

  err = .false.
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'q', qa, &
    & quiet = .true., err = err, flag_mpi_split=.true. )
  call AssertEqual('shape consistency test 1', answer = .true., check = err)

  deallocate ( qa )
  allocate( qa (nx,ny,nz) )

  err = .true.
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'q', qa, err = err, flag_mpi_split=.true. )
  call AssertEqual('shape consistency test 2', answer = .false., check = err)

  !-------------------------------------------------------------------
  !  ãƒã‚¤ãƒ³ã‚¿é…åˆ—ã«ã‚ˆã‚‹å…¥åŠ›ãƒ†ã‚¹ãƒˆ (è‰²ã€…ãªä½œæ³•ã§å…¥åŠ›)
  !-------------------------------------------------------------------

  call HistoryCreate(file='xhistget_mpi/xhistget3.nc', &
    & title='gtool_history HistoryGet test 1', &
    & source='gtool5/Fortran library test kit', &
    & institution='GFD Dennou Club', &
    & dims=(/'x','y','z','t'/), &
    & dimsizes=(/nx,ny,nz,0/), &
    & longnames=(/'X-coordinate','Y-coordinate', &
    &  'Z-coordinate','time        '/), &
    & units=(/'m','m','m','s'/), &
    & origin=0.0, interval=0.2, &
    & xtypes=(/'real  ','double','double','real  '/), &
    & flag_mpi_split=.true. )

  call HistoryPut('x',x)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('y',y)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('z',z)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›

  call HistoryAddVariable('scalar', dims=(/''/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('u', dims=(/'t'/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('v', dims=(/'x','t'/), &
    & longname='1 Dimensional any quantity', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('v2', dims=(/'z','t'/), &
    & longname='1 Dimensional any quantity II', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('w', dims=(/'x','y','t'/), &
    & longname='2 Dimensional any quantity', &
    & units='2-dimensional any unit', xtype='int')
  call HistoryAddVariable('q', dims=(/'x','y','z','t'/), &
    & longname='3 Dimensional any quantity', &
    & units='3-dimensional any unit', xtype='double')

  call HistoryGetPointer(file='xhistget_mpi/xhistget1.nc', varname='scalar', &
    & array=up, flag_mpi_split=.true.)
  call HistoryPut('scalar', up)
  deallocate(up)
  do, l = 1, time_period - 1
    call HistoryPut('t', real(l)*0.2)
    call HistoryGetPointer(file='xhistget_mpi/xhistget1.nc', varname='u', &
      &          array=up, time=real(l, DP) * 0.2_DP, flag_mpi_split=.true. )
    call HistoryPut('u', up)
    deallocate(up)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v', vp, dble(l)*0.2_DP, flag_mpi_split=.true.)
    call HistoryPut('v', vp)
    deallocate(vp)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v2', vp, range='t=^'//toChar(l), flag_mpi_split=.true.)
    call HistoryPut('v2', vp)
    deallocate(vp)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'w', wp, time=real(l)*0.2, flag_mpi_split=.true.)
    call HistoryPut('w', wp)
    deallocate(wp)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'q', qp, 't=^'//toChar(l), flag_mpi_split=.true.)
    call HistoryPut('q', qp)
    deallocate(qp)
  enddo

  !---------------------------
  !  æ™‚é–“ã®è‡ªå‹•åˆ¤åˆ¥ã®ãƒ†ã‚¹ãƒˆ
  l = time_period
  call HistoryPut('t', real(l)*0.2)
  call HistoryGetPointer(file='xhistget_mpi/xhistget1.nc', varname='u', array=up, flag_mpi_split=.true.)
  call HistoryPut('u', up)
  deallocate(up)
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v', vp, range='', flag_mpi_split=.true.)
  call HistoryPut('v', vp)
  deallocate(vp)
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v2', vp, dble(l)*0.2_DP, flag_mpi_split=.true.)
  call HistoryPut('v2', vp)
  deallocate(vp)
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'w', wp, flag_mpi_split=.true.)
  call HistoryPut('w', wp)
  deallocate(wp)
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'q', qp, 't=^'//toChar(l), flag_mpi_split=.true.)
  call HistoryPut('q', qp)
  deallocate(qp)

  call HistoryClose

  !-------------------------------------------------------------------
  !  æ¬¡å…ƒãƒ‡ãƒ¼ã‚¿ã®å…¥åŠ›ãƒ†ã‚¹ãƒˆ (è‰²ã€…ãªä½œæ³•ã§å…¥åŠ›)
  !-------------------------------------------------------------------
  call MessageNotify('M', subname, 'Getting by Various Forms.')

  call HistoryCreate(file='xhistget_mpi/xhistget4.nc', &
    & title='gtool_history HistoryGet test 1', &
    & source='gtool5/Fortran library test kit', &
    & institution='GFD Dennou Club', &
    & dims=(/'x','y','z','t'/), &
    & dimsizes=(/nx,ny,nz,0/), &
    & longnames=(/'X-coordinate','Y-coordinate', &
    &  'Z-coordinate','time        '/), &
    & units=(/'m','m','m','s'/), &
    & origin=0.0, interval=0.2, &
    & xtypes=(/'real  ','double','double','real  '/), &
    & flag_mpi_split=.true.)

  ! æ¬¡å…ƒãƒ‡ãƒ¼ã‚¿ã‚’å…¥åŠ›ã™ã‚‹
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'x' ,xp, flag_mpi_split=.true.)   ! x æ¬¡å…ƒå…¥åŠ›
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'y' ,yp, flag_mpi_split=.true.)   ! y æ¬¡å…ƒå…¥åŠ›
  call HistoryGetPointer(file='xhistget_mpi/xhistget1.nc', varname='z' ,array=zp, flag_mpi_split=.true.)   ! z æ¬¡å…ƒå…¥åŠ›

  call HistoryPut('x',xp)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('y',yp)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›
  call HistoryPut('z',zp)   ! æ¬¡å…ƒå¤‰æ•°å‡ºåŠ›

  call HistoryAddVariable('scalar', dims=(/''/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('u', dims=(/'t'/), &
    & longname='Non Dimensional any quantity', &
    & units='non-dimensional')
  call HistoryAddVariable('v', dims=(/'x','t'/), &
    & longname='1 Dimensional any quantity', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('v2', dims=(/'z','t'/), &
    & longname='1 Dimensional any quantity II', &
    & units='1-dimensional any unit', xtype='double')
  call HistoryAddVariable('w', dims=(/'x','y','t'/), &
    & longname='2 Dimensional any quantity', &
    & units='2-dimensional any unit', xtype='int')
  call HistoryAddVariable('q', dims=(/'x','y','z','t'/), &
    & longname='3 Dimensional any quantity', &
    & units='3-dimensional any unit', xtype='double')

  call HistoryGetPointer(file='xhistget_mpi/xhistget1.nc', varname='scalar', &
    & array=up, flag_mpi_split=.true.)
  call HistoryPut('scalar', up)
  deallocate(up)
  do, l = 1, time_period
    call HistoryPut('t', real(l)*0.2)
    call HistoryGetPointer(file='xhistget_mpi/xhistget1.nc', varname='u', &
      &          array=up, time=real(l) * 0.2, flag_mpi_split=.true. )
    call HistoryPut('u', up)
    deallocate(up)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v', vp, dble(l)*0.2_DP, flag_mpi_split=.true.)
    call HistoryPut('v', vp)
    deallocate(vp)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v2', vp, range='t=^'//toChar(l), flag_mpi_split=.true.)
    call HistoryPut('v2', vp)
    deallocate(vp)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'w', wp, time=real(l)*0.2, flag_mpi_split=.true.)
    call HistoryPut('w', wp)
    deallocate(wp)
    call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'q', qp, 't=^'//toChar(l), flag_mpi_split=.true.)
    call HistoryPut('q', qp)
    deallocate(qp)
  enddo

  call HistoryClose

  !-------------------------------------------------------------------
  !  returned_value ã¨ flag_time_exist ã®ãƒ†ã‚¹ãƒˆ
  !-------------------------------------------------------------------
  call HistoryGet('xhistget_mpi/xhistget1.nc', 'scalar', u, &
    & returned_time = rettime, flag_time_exist = texist, flag_mpi_split=.true. )
  call AssertEqual('returned_time test 1', &
    & answer = int(rettime * 10000), check = 0 )
  call AssertEqual('flag_time_exist test 1', &
    & answer = texist, check = .false. )

  call HistoryGet('xhistget_mpi/xhistget1.nc', 'u', u, &
    & returned_time = rettime, flag_time_exist = texist, flag_mpi_split=.true. )
  call AssertEqual('returned_time test 2', &
    & answer = int(rettime * 10000), check = 6000 )
  call AssertEqual('flag_time_exist test 2', &
    & answer = texist, check = .true. )

  call HistoryGet('xhistget_mpi/xhistget1.nc', 'u', u, time=0., &
    & returned_time = rettime, flag_mpi_split=.true. )
  call AssertEqual('returned_time test 3', &
    & answer = int(rettime * 10000), check = 2000 )

  if (associated(vp)) deallocate(vp)
  call HistoryGetPointer('xhistget_mpi/xhistget1.nc', 'v', vp, range='t=0.35', &
    & returned_time = rettime, flag_mpi_split=.true. )
  if (associated(vp)) deallocate(vp)
  call AssertEqual('returned_time test 4', &
    & answer = int(rettime * 10000), check = 4000 )

  if ( associated(up) ) deallocate(up)
  if ( associated(vp) ) deallocate(vp)
  if ( associated(wp) ) deallocate(wp)
  if ( associated(qp) ) deallocate(qp)
  if ( associated(xp) ) deallocate(xp)
  if ( associated(yp) ) deallocate(yp)
  if ( associated(zp) ) deallocate(zp)
  if ( associated(vp_range) ) deallocate(vp_range)
  if ( associated(qp_range) ) deallocate(qp_range)

  !-----------------------------------------------------------------
  !  MPI çµ‚äº†å‡¦ç†
  !-----------------------------------------------------------------
  call MPI_Finalize(err_mpi)

end program histget