I need to write some data to file in Fortran 90. How should I use WRITE (*,*) input to have the values grouped in columns? WRITE always puts a new line after each call, that’s the problem.
code example:
open (unit = 4, file = 'generated_trajectories1.dat', form='formatted')
do time_nr=0, N
write (4,*) dble(time_nr)*dt, initial_traj(time_nr)
end do
And now the point is to have it written in separate columns.
You can use implied DO loops to write values as single records. Compare the following two examples:
It produces:
Using implied DO loops it can rewritten as:
This one produces:
If the number of elements is not fixed at compile time, you can either use the
<n>extension (not supported bygfortran):It takes the number of repetitions of the
(2I4)edit descriptor from the value of the variablen. In GNU Fortran you can first create the appropriate edit descriptor using internal files:Of course, it also works with list directed output (that is output with format of
*):