|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Kenneth_Smith
Joined: 18 May 2012 Posts: 709 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Mon Apr 03, 2023 12:24 pm Post subject: Can TRANSPOSE be permitted in an initialisation expression? |
|
|
I do not recall if this has been discussed before.
The TRANSPOSE intrinsic function is not permitted in an initialisation expression in FTN95 (while RESHAPE is permitted).
gFortran and iFort do allow the use of TRANSPOSE in this situation.
It would help, when receiving code written in these alternative compilers, if FTN95 also allowed the use of TRANSPOSE in an initialisation.
For example for:
Code: | 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))) ! Not permitted in FTN95
open(unit=10,file='temp.txt',status='unknown') ; rewind 10
do row = 1, n
write(10,*), (a(row,col), col=1,n)
end do
rewind 10 ; close(unit=10,status='keep')
end program p |
both of the alternative compilers returns for the above code:
1.000000 2.000000 3.000000
4.000000 5.000000 6.000000
7.000000 8.000000 9.000000
Not urgent, the source code I received has been modified to be compatible with FTN95, but something to perhaps consider - time permitting? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
Posted: Tue Apr 04, 2023 2:04 pm Post subject: |
|
|
Ken
Thank you for the feedback.
I have added this to the wish list. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
Posted: Tue Apr 18, 2023 11:17 am Post subject: |
|
|
This has now been implemented for the next release of FTN95. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 709 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Mon Jul 10, 2023 11:01 pm Post subject: |
|
|
Paul,
The following code runs as expected, now that the TRANSPOSE intrinsic is allowed in an initialisation expression.
Code: | 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:
Code: | 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: | 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.
Code: | 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.:
Code: | 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! |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
Posted: Tue Jul 11, 2023 7:21 am Post subject: |
|
|
Ken
Thanks for the feedback. I have made a note of this. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
Posted: Wed Nov 01, 2023 12:49 pm Post subject: |
|
|
The failure of TRANSPOSE with PARAMETER has now been fixed for a future release of FTN95. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 709 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Mon Nov 06, 2023 12:02 pm Post subject: |
|
|
Paul, thanks for this fix. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|