First of all I must say I'm new to Fortran and I'm very excited about it's power for my area which is computational fluid dynamics (CFD).
But I have just found a bug which I can't seem to find the answer to. I want to make a simple thing: print an array (ok, I did it fine), and before that array I want to print either a new line (using print '(/)') or just print the array's name, like "P = ". The reason for this is because my array is calculated in many iterations and I want to see the progress of each iteration, so I want them to be separated by something.
But when I insert the code to print either one of these lines inside my function, my array which was previously being shown as numbers during all iterations, starts showing as NaN after some iterations. Does anyone know what can I do to be able to fix this? And can someone explain to me why this happens in Fortran? Like, why does a simple print statement changes the logic?
I would normally insert my "print '(/)' " anywhere inside the q = 0,nit loop, but outside the i,j loops and that is what makes it ??change the logic? of the program?
function pressure_poisson(p,dx,dy,nit,nx,ny)
real, dimension(10,10) :: pressure_poisson,p,pn
real :: dx, dy
integer :: i,j, q, nit, nx, ny
do q = 0,nit
pn = p
do i = 1,nx
do j = 1,ny
p(i,j) = ((( pn (i+1,j) + pn (i-1,j) )* dy ** 2 + &
( pn(i,j+1) + pn (i, j-1) ) * dx **2 ) / (2 * (dx**2 + dy ** 2)) - &
dx **2 * dy **2 / (2 * (dx **2 + dy **2)) * b(i,j))
end do
end do
do i = 1,nx
do j = 1, ny
write (*,'(3x, es10.3)', advance='no'), p(i,j)
end do
print '(/)'
end do
end do