Reputation: 5927
In fortran, is it possible to index into elements of an array subject to an intrinsic? I am referring in particular to the transpose
function. In the following code, I am generating and initializing an array named A and trying to index into a value inside the transposed array
program test
integer, dimension(5,3) :: A
integer :: i,j
A = reshape((/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15/), shape(A))
print *, transpose(A)(1,1)
end program test
however I am getting a syntax error as follows:
**D:\TEMP\FortranTest>gfortran -o Test Transposecommand.f90 Transposecommand.f90:11:22:
print *, transpose(A)(1,1) 1 Error: Syntax error in PRINT statement at (1)**
It there a way to accomplish this without having to declare a separate variable then assign the transposed array to it? I would like to avoid declaring new variables if possible...
Upvotes: 1
Views: 82
Reputation: 78364
No, Fortran doesn't support that kind of indexing into function results. You'll have to devise an elegant solution of your own (aka a kludge). My own would take account of
transpose(a)(i,j) == a(j,i)
Upvotes: 1