Below is my program that prints a 2d array. First, is it OK to use an empty write statement to start a new line? Second, why advance = “no” rather than advance = .false.?
program main
real :: x(5, 5)
integer :: i, j
call random_number(x)
x = x - 0.5
do i = 1, 5
do j = 1, 5
write(*, "(f8.2)", advance = "no") x(i, j)
end do
write(*, *)
end do
end program
You can do it that way, but it is simpler to use an unlimited format, as shown below:
program main
real :: x(5, 5)
integer :: i, j
call random_number(x)
x = x - 0.5
do i = 1, 5
do j = 1, 5
write(*, "(f8.2)", advance = "no") x(i, j)
end do
write(*, *)
end do
write (*, *)
do i=1, 5
write (*,"(*(f8.2))") x(i,:) ! unlimited format
end do
end program
I think the standard writers wanted to allow for such possibilities as advance='maybe'. Restricting the possibilities to only .true. or .false. might have appeared too limiting at the time it was included in the language.
For added complexity you can use a colon edit descriptor to add content between array elements, but not after the data is exhausted.
A simple example is to place a comma between array elements, but not after the last item
program main
real :: x(5, 5)
integer :: i
call random_number(x)
x = x - 0.5
do i = 1, size(x,dim=1)
write (*,"(*(f8.2,:,','))") x(i,:) ! unlimited format
end do
end program