!= 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_attr.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 HistoryAddAttr('temp','gt_graph_tick_all',1)
  call HistoryAddAttr('temp','gt_graph_contour_spacing',(/0.0,1.0,0.01/))
  call HistoryAddAttr('temp','+gt_user_davis_kappa',kappa)

  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