I want to initialize an array on one line with an implicit do loop. However, I always get a syntax or shape error. Can anyone help me correct the following construc
The implicit do loop will only create a vector so you'll have to reshape that. Something like this:
integer, dimension(m,n) :: myarray
integer :: ix, jx
...
myarray = reshape( [ (ix, ix = 1, m*n) ], [ m, n ] )
or perhaps you want a more complicated, nested, implied-do loop:
myarray = reshape( [ ((ix+jx, ix = 1, m), jx = 1, n) ], [ m, n ] )
Note that I'm using the Fortran2003 convention of [ ]
to delimit array constructions, rather than (/ /)
. Note also that you have to declare the implied do loop index variables.