PROGRAM adv1d
!===================================================
!  TD2 program, MON/OACOS 2014-2015
!===================================================

!---------------------------------------------------
! Declaration
!---------------------------------------------------

IMPLICIT NONE
integer,parameter :: imax=100
integer :: choix_initial=0
real,dimension(imax) :: xxx,qinitial,qexact
integer :: i,it
real :: wind=10.
real :: time,deltat

real :: xmax=1000.,deltax
real :: pi,x0,lambda,a1,a2,a3

character*4 file_name

deltax=xmax/float(imax)
pi=2.*asin(1.)
deltat=0.2*deltax/wind

!===================================================
! Initialisation : 2 cas
!===================================================

do i=1,imax
   xxx(i)=i*deltax
enddo
if (choix_initial==0) then
   lambda=xmax/15.
   x0=xmax/5.
   qinitial(:)=exp( -((xxx(:)-x0)/lambda)**2 )
else
   a1=4.
   a2=17.
   a3=0.5
   do i=1,imax
      qinitial(i)=sin(a1*pi*xxx(i)/xmax)+sin(a2*pi*xxx(i)/xmax)+a3*(-1.+2*mod(i,2))
   enddo
endif

file_name="q..."
write(file_name(2:4),'(i3.3)') 0
open (10,file=file_name,form='formatted')
do i=1,imax
   write(10,*) xxx(i),qinitial(i)
enddo
close(10)


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Time loop
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
do it=1,500
   time=it*deltat
   qexact(:)=exp( -((xxx(:)-wind*time-x0)/lambda)**2 )

   if ( mod(it,20) == 1 ) then
      file_name="e..."
      write(file_name(2:4),'(i3.3)') it
      open (10,file=file_name,form='formatted')
      do i=1,imax
         write(10,*) xxx(i),qexact(i)
      enddo
      close(10)
   endif
enddo

end

