!= Sample program for gtool_history/gtool5
!
! * 2006/10/25 Y.Morikawa
! * 2003/08/21 M.Odaka
! * 2001/02/27 S.Takehiro
!
! Solving diffusion equation
! \[
!     du/dt = \kappa d^2 u/dx^2
! \]
! for giving values of $u$ at $x=[0,1]$.
!
program diffusion

  use gtool_history                                   ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«æŒ‡å®š

  integer, parameter     :: nx=30                   ! ã‚°ãƒªãƒƒãƒ‰æ•°
  integer, parameter     :: nt=200                  ! æ™‚é–“ã‚¹ãƒ†ãƒƒãƒ—æ•°
  integer, parameter     :: ndisp=10                ! å‡ºåŠ›é–“éš”
  real(8), parameter     :: dx=1.0/(nx-1)           ! ã‚°ãƒªãƒƒãƒ‰é–“éš”
  real(8), parameter     :: dt=0.0005               ! æ™‚é–“é–“éš”
  real(8), dimension(nx) :: x=(/(dx*(i-1),i=1,nx)/) ! åº§æ¨™å¤‰æ•°
  real(8), dimension(nx) :: temp                    ! æ¸©åº¦
  real(8), parameter     :: kappa=1.0               ! ç†±æ‹¡æ•£ä¿‚æ•°

  tinit = 0.0                                       ! åˆæœŸæ™‚åˆ»è¨å®š

  temp = exp(-((x-0.5)/0.1)**2)                     ! åˆæœŸå€¤è¨å®š

  call HistoryCreate( &                             ! ãƒ’ã‚¹ãƒˆãƒªãƒ¼ä½œæˆ
    & file='diffusion_1.nc', title='Diffusion equation', &
    & source='Sample program of gtool_history/gtool5',   &
    & institution='GFD_Dennou Club davis project',       &
    & dims=(/'x','t'/), dimsizes=(/nx,0/),               &
    & longnames=(/'X-coordinate','time        '/),       &
    & units=(/'m','s'/),                                 &
    & origin=real(tinit), interval=real(ndisp*dt) )

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

  call HistoryAddVariable( &                        ! å¤‰æ•°å®šç¾©
    & varname='temp', dims=(/'x','t'/), &
    & longname='temperature', units='K', xtype='double')

  call HistoryPut('temp',temp)                      ! å¤‰æ•°å‡ºåŠ›

  do it=1,nt
    temp(2:nx-1) = temp(2:nx-1) &                   ! æ™‚é–“ç©åˆ†
      & + kappa*(temp(3:nx)-2*temp(2:nx-1)+temp(1:nx-2))/dx**2*dt

    if ( mod(it,ndisp) == 0 ) then
      call HistoryPut('temp',temp)                  ! å¤‰æ•°å‡ºåŠ›
    endif
  enddo

  call HistoryClose
  stop
end program diffusion