simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Wed Jan 27, 2021 1:07 pm Post subject: Multiple rank part references |
|
|
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 |
|