Paul,
The following code runs as expected, now that the TRANSPOSE intrinsic is allowed in an initialisation expression.
program p
implicit none
integer row, col
integer, parameter :: n = 3
real :: a(n,n) = transpose(reshape([1,2,3,4,5,6,7,8,9],shape(a)))
do row = 1, n
write(*,*) (a(row,col), col=1,n)
end do
end program p
However, if the real array a is given the parameter attribute, as in:
program p
implicit none
integer row, col
integer, parameter :: n = 3
real, parameter :: a(n,n) = transpose(reshape([1,2,3,4,5,6,7,8,9],shape(a)))
do row = 1, n
write(*,*) (a(row,col), col=1,n)
end do
end program p
The complier says:
,shape(a)))
do row = 1, n
write(,) (a(row,col), col=1,n)
end do
end program p
However, if the real array a is given the parameter attribute, as in:
program p
implicit none
integer row, col
integer, parameter :: n = 3
real, parameter :: a(n,n) = transpose(reshape([1,2,3,4,5,6,7,8,9],shape(a)))
do row = 1, n
write(*,*) (a(row,col), col=1,n)
end do
end program p
The complier says:
[quote:3bbf7ede05]FreeFormat7.F95(6) : error 898 - Constant found on left hand side of an assignment where a variable was expected
Simplifying the code further, so there is no DO LOOP or implied do loop i.e. just a simple print*, as in the following, the same error is still reported.
program p
implicit none
integer row, col
integer, parameter :: n = 3
real, parameter :: a(n,n) = transpose(reshape([1,2,3,4,5,6,7,8,9],shape(a)))
print*, a
end program p
If a has the parameter attribute, but transpose is not used (only reshape), there is no issue attempting to print the array a i.e.:
program p
implicit none
integer row, col
integer, parameter :: n = 3
real, parameter :: a(n,n) = (reshape([1,2,3,4,5,6,7,8,9],shape(a)))
do row = 1, n
write(*,*) (a(row,col), col=1,n)
end do
end program p
Very strange! Perhaps I am trying to do too much at compile time, the code which identified this issue was more complex than these reduced examples.
One for you to look at when you have the opportunity. Apologies for adding to your to-do list once again. Perphaps Dan is correct when he says I use too many tricks!