soccer jersey forums.silverfrost.com :: View topic - Can TRANSPOSE be permitted in an initialisation expression?
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can TRANSPOSE be permitted in an initialisation expression?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions
View previous topic :: View next topic  
Author Message
Kenneth_Smith



Joined: 18 May 2012
Posts: 709
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Apr 03, 2023 12:24 pm    Post subject: Can TRANSPOSE be permitted in an initialisation expression? Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8012
Location: Salford, UK

PostPosted: Tue Apr 04, 2023 2:04 pm    Post subject: Reply with quote

Ken

Thank you for the feedback.

I have added this to the wish list.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8012
Location: Salford, UK

PostPosted: Tue Apr 18, 2023 11:17 am    Post subject: Reply with quote

This has now been implemented for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 709
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Jul 10, 2023 11:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8012
Location: Salford, UK

PostPosted: Tue Jul 11, 2023 7:21 am    Post subject: Reply with quote

Ken

Thanks for the feedback. I have made a note of this.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8012
Location: Salford, UK

PostPosted: Wed Nov 01, 2023 12:49 pm    Post subject: Reply with quote

The failure of TRANSPOSE with PARAMETER has now been fixed for a future release of FTN95.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 709
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Nov 06, 2023 12:02 pm    Post subject: Reply with quote

Paul, thanks for this fix.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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