Depending on the output format you desire, you would not necessarily need a do-loop, here is the simplest:
program simple
implicit none
CHARACTER(len=1) :: Grid(2,2)
Grid = reshape( ["1","2","3","4"] , shape=shape(Grid) )
write( * , "(A)" ) Grid
end program simple
The line with reshape
, uses the Fortran >2003 array constructor syntax []
. So make sure your compiler settings already is set to Fortran 2008 standard. Otherwise, simply replace []
with the old array constructor syntax (//)
.
If you want each row to be printed on a different line, then looping would be necessary, at least, an implied do-loop,
program simple
implicit none
integer :: i,j
integer, parameter :: n=2
CHARACTER(len=1) :: Grid(n,n)
Grid = reshape( ["1","2","3","4"] , shape=shape(Grid) )
write( * , "(*(g0))" ) ( (Grid(i,j)," ",j=1,n), new_line("A"), i=1,n )
end program simple
The above version, I believe, avoids the unnecessary temporary array created by the compiler to store the non-contagious array section Grid(i,:)
, before printing it to the output. The g0
edit descriptor is a handy feature of Fortran 2008. So make sure you compiler supports Fortran 2008 standard.