I have a problem with writing results on a file in Fortran. Here's a code as an example:
program test
implicit none
real,dimension(5) ::x
integer ::i
x = (/1, 2, 3, 4, 5/)
open(unit=40,file="test.dat")
do i=1,5
read(*,*)
write(40,*)x(i)**2
end do
close(unit=40)
end program
This returns the file test.dat with the following
1.00000000
4.00000000
9.00000000
16.0000000
25.0000000
The do-loop advances as I press "Enter", and, in theory, every time the do-loop advances, it should write on the file the correspondent value of x(i)^2. However, after the first iteration, it doesn't write anything until the code as ended, at which point it writes the missing 4 other values.
I need the code to write the results "in real time" in each iteration, not all at once after the code has ended. Is that possible?
Thanks for the help.