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 

Multiple rank part references

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



Joined: 05 Jul 2006
Posts: 177

PostPosted: Wed Jan 27, 2021 1:07 pm    Post subject: Multiple rank part references Reply with quote

Imagine a derived-type array, and the derived type itself contains an array. Is it possible to reference the data using Fortran's array notation for both arrays? I am not quite sure how to ask the question properly, but my example below hopefully illustrates what I mean. The second executable line is commented out because it generates a compilation error. If the syntax were valid, a subsequent question would be how to use such syntax in a subroutine call? For example, would the last (commented) line before Contains, be considered reasonable - could we not interpret the resulting argument as a two-dimensional array?

Code:
Program p
   Integer, Parameter :: n = 3
   Type t
     Integer, Dimension(n) :: i
   End Type t
   Type(t) :: t1
   Type(t), Dimension(n) :: t2
!
   t1%i(:) = 1
!   t2(:)%i(:) = 1 ! What is valid syntax for this line?
   t2(:)%i(1) = 2
   t2(:)%i(2) = 2
   t2(:)%i(3) = 2
   Call s1 (t1%i(:))
   Call s2 (t2(:)%i(1))
!   Call s3 (t2(:)%i(:)) ! How could a subroutine be called?
!
Contains
 Subroutine s1 (i)
   Integer, Dimension(:), Intent(In) :: i
   Print*, 's1', i
 End Subroutine s1
 Subroutine s2 (i)
   Integer, Dimension(:), Intent(In) :: i
   Print*, 's2', i
 End Subroutine s2
 Subroutine s3 (i)
   Integer, Dimension(:,:), Intent(In) :: i
   Print*, 's3', i
 End Subroutine s3
End Program p


Incidentally, I came across the following page while trying to investigate this issue, but I do not know what the outcome was:
https://fortran.bcs.org/2005/newreqs/multi_part_refs.txt
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Wed Jan 27, 2021 3:59 pm    Post subject: Reply with quote

Simon

You can write

t2(1)%i = v

or

t2%i(1) = v

but you can't do both together.

If you want to pass the whole lot then I guess the call would be

CALL s3(t2)

where s3 would have the corresponding interface.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support 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