Silverfrost Forums

Welcome to our forums

Bug with array sections involving Derived Types

31 Jul 2011 6:32 #8665

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
1 Aug 2011 5:58 #8669

OK. I have logged this as a bug that needs fixing.

16 Nov 2011 5:49 #9230

This bug has now been fixed for the next release.

18 Nov 2011 6:29 #9248

Thanks Paul.

Please login to reply.