In Fortran 90/95, array sections can be formed from arrays of derived types. However, it does not work in FTN95 if the derived type component is an array.
In the following code, the compiler complains that foo(:)%a(1) and has extent 1 and b has extent 10. But, actually they both have extent 10.
I get similar errors [u:700444cd13]at run time[/u:700444cd13] using most of the intrinsics which expect arrays (pack, minval, maxval etc.)
I discovered this today; I am trying to pack a derived type array section under the control of a MASK so I can pass it to my own subroutine.
It seems the compiler is confusing the dimensions of a and foo. (It compiles if a and foo are both dimension 10).
It also works if the component variables is not an array.
Hope this is clear; its kind of difficult to explain.
program anon
type :: foo_type
real :: a(1)
end type foo_type
integer i
type(foo_type) :: foo(10) !< Array of derived type
real :: b(10)
! Assign some values
do i=1, 10
foo(i)%a(1) = 1.0
end do
! Compiler thinks RHS has extent 1 (but its extent 10)
! error 331 - Non-conformant array shapes in first rank of an array expression (10 and 1)
b = foo(:)%a(1)
! The next line works (I think)
!forall(i=1:10) b(i)=foo(i)%a(1)
! This doesn't work
! print *, maxval(foo(:)%a(1))
! This doesn't work either.
! call my_array_proc( pack(foo(:)%a(1), flags(:)) )
do i=1, 10
print *, b(i)
end do
end program anon