I am trying to code the following pseudo-code to approximate the solution to the 1D linear convection as in the figure:
http://imageshack.us/photo/my-images/708/fig1s.jpg/
Here is what I have done so far,
PROGRAM one_d_linear_convection
IMPLICIT NONE
INTEGER::i,it,nx,nt,k
DOUBLE PRECISION::dx,dt,c
DOUBLE PRECISION,DIMENSION(1:20)::u,un
nx=20
nt=50
dt=0.01
c=1.0
dx=2./(nx-1.)
!initial condition
DO i = 1,nx
IF (i*dx>=0.5 .and. i*dx<=1) THEN
u(i) = 2
ELSE
u(i) = 1
ENDIF
! WRITE(*,*)i,u(i)
ENDDO
!Finite Difference
DO it=1,nt
DO k=0,nx-1
un(k)=u(k)
DO i=2,nx-1
u(i) = un(i) - c*dt/dx*(un(i)-un(i-1))
WRITE(*,*)i,u(i)
ENDDO
ENDDO
ENDDO
END
My problem is I cant figure a way out to see the arrays and the u value at x=1 and 20. Any help would be highly appreciated.
Thanks!