! Sample program for gtool_history/gtool4              2001/02/27 S.Takehiro
! 
! Solving diffusion equation 
!     du/dt = kappa d^2 u/dx^2
! for giving values of u at x=0 and 1. 
!
program diffusion

  integer, parameter              :: nx=30                   ! $B%0%j%C%I?t(B
  integer, parameter              :: nt=200                  ! $B;~4V%9%F%C%W?t(B
  integer, parameter              :: ndisp=10                ! $B=PNO4V3V(B
  double precision, parameter     :: dx=1.0/(nx-1)           ! $B%0%j%C%I4V3V(B
  double precision, parameter     :: dt=0.0005               ! $B;~4V4V3V(B
  double precision, dimension(nx) :: x=(/(dx*(i-1),i=1,nx)/) ! $B:BI8JQ?t(B
  double precision, dimension(nx) :: temp                    ! $B29EY(B
  double precision, parameter     :: kappa=1.0               ! $BG.3H;678?t(B

  temp = exp(-((x-0.5)/0.1)**2)                              ! $B=i4|CM@_Dj(B

  do it=1,nt
     temp(2:nx-1) = temp(2:nx-1) &                           ! $B;~4V@QJ,(B
          +kappa*(temp(3:nx)-2*temp(2:nx-1)+temp(1:nx-2))/dx**2*dt

     if ( mod(nt,ndisp) .eq. 0 ) then
        write(6,*)it*dt                                      ! $BJQ?t=PNO(B
        write(6,*)temp                                       ! $BJQ?t=PNO(B
     endif
  enddo

  stop
end program diffusion
