View Single Post
s_hy
#1
Mar5-12, 01:49 AM
P: 57
dear all,

i have a code with line segmentation fault error. please anyone advice me how to debug this code. thank you...

##################################################################

Program Main

IMPLICIT NONE

call fd1d

return
END PROGRAM Main


! 1d scalar wave equation with fd method and stability condition = 1
SUBROUTINE fd1d
implicit none

real,dimension(1) :: x
real :: x_delta
real :: t_delta
real :: c
real :: xlast
real :: xinit
real :: tinit
real :: tlast
real :: k
real :: x0
real,dimension(:,,allocatable :: u
real :: alpha
integer :: iinit
integer :: ilast
integer :: ninit
integer :: nlast
integer :: i
integer :: n
real, parameter :: pi = 3.141592654

allocate (u(0:200,0:600))

!initialisation
c = 300
x_delta = 0.005
t_delta = x_delta/c
alpha = c*t_delta/x_delta
xlast = 1.0
xinit = 0
iinit = 0
ilast = int ((xlast-xinit)/x_delta)
tlast = 0.01
tinit = 0
ninit = 0
nlast = int ((tlast-tinit)/t_delta)
x(iinit) = xinit
x(ilast) = xlast

!initial profile
k = 1000.0
x0 = 0.3
do i = iinit,ilast
u(i,0) = 0.0
u(i,-1) = 0.0
end do

open (unit=100,file='n0.dat',action='write')
do i = iinit, ilast
x(i) = x(iinit) + i*x_delta
u(i,0) = exp (-k*(x(i)-x0)**2)
u(i,-1) = exp (-k*(x(i)-x0)**2)
Print *, u(i,0)
write (*,*) u(i,0)
end do
close (unit = 100)

open (unit=110,file='n1.dat',action='write')
do n = 0,nlast
do i = iinit,ilast
u(i,n+1) = 2*(1-(alpha**2))*u(i,n)-u(i,n-1)+(alpha**2)*(u(i+1,n)+u(i-1,n))
end do !i

!boundary condition
u(0,n+1) = 0
u(ilast,n+1) = 0
!end of boundary condition
!export data
print *, u(i,n+1)
write (110,*) u(i,n+1)
end do !n
close (unit = 110)

return
end SUBROUTINE fd1d
Phys.Org News Partner Science news on Phys.org
'Office life' of bacteria may be their weak spot
Lunar explorers will walk at higher speeds than thought
Philips introduces BlueTouch, PulseRelief control for pain relief