Allocatable Derived Type Arrays in Derived Types


It seems that, allocatable derived type arrays has some problems in 11.8.

When I defined a allocatable derived type array under some other derived types, Sometimes it looses lower and upper bound information when passed to a subroutine. For example

Call Print (Inputs%Initializers%Boundary_Distribution%AtDimsAndFaces)

Call Print (Inputs%Initializers%Boundary_Distribution)

First call works but second one fails. In the second call I get really weird values from LBOUND and UBOUND functions. (Here, AtDimsAndFaces is a allocatable derived type array and second subroutine calls the first one if the array allocated)

Code of the first print routine is;

  SUBROUTINE PRINT_Initializers_At_Dimension_And_Face_Class_Array_2D (InitializersArray)
!    Type (Initializers_At_Dimension_And_Face_Class) ,Intent(In) ,Allocatable :: InitializersArray (:,:)                                                                                                                                 
    Type (Initializers_At_Dimension_And_Face_Class) ,Intent(In) :: InitializersArray (:,:)
    Logical :: Allocated_Component
    Integer :: LowerBounds(2), UpperBounds(2), I, J

!    Allocated_Component = ALLOCATED (InitializersArray)                                                                                                                                                                                 
    Allocated_Component = .TRUE.

    If (Allocated_Component) then

      LowerBounds = LBOUND (InitializersArray)
      UpperBounds = UBOUND (InitializersArray)

      Write (*,*) " Lower Bounds ", LowerBounds
      Write (*,*) " Upper Bounds ", UpperBounds

      Do J = LowerBounds(2), UpperBounds(2)

         Do I = LowerBounds(1), UpperBounds(1)
             Write (*,*) " "
             Write (*,*) "  Element Index =>", I, J
             Call PRINT_Initializers_At_Dimension_And_Face_Class (InitializersArray(I,J))

         End Do
      End Do

  END SUBROUTINE PRINT_Initializers_At_Dimension_And_Face_Class_Array_2D

Note that 2 lines are commented out. This is a another problem; If I define this array as allocatable in the subroutine interface, it completely fails. (I get “0: LBOUND: arg not associated with array”)

Code of other print subroutine (which fails to get bound values) is;

  SUBROUTINE Print_Initializers_Boundary_Distribution_Class (Initializers)
    Type (Initializers_Boundary_Distribution_Class) ,Intent(In) :: Initializers
    Logical :: Allocated_Component

    Allocated_Component = ALLOCATED (Initializers%Allocators)
    If (Allocated_Component) then

       Call Print_Allocators_Boundary_Distribution_Class (Initializers%Allocoters)
       Write (*,*) "  Allocators   => NOT ALLOCATED "
    End If
    Allocated_Component = ALLOCATED (Initializers%AtDimsAndFaces)
    If (Allocated_Component) then

       Write (*,*) SIZE (Initializers%AtDimsAndFaces)
       Write (*,*) LBOUND (Initializers%AtDimsAndFaces), UBOUND (Initializers%AtDimsAndFaces)

       Call PRINT_Initializers_At_Dimension_And_Face_Class_Array_2D (Initializers%AtDimsAndFaces)


       Write (*,*) "  AtDimsAndFaces => NOT ALLOCATED"

    End If

  END SUBROUTINE Print_Initializers_Boundary_Distribution_Class

I have added SIZE, LBOUND and UBOUND after, to see where the information get lost…

Definition of this derived types are;

TYPE ,PUBLIC ,EXTENDS (Initializer_Base_Class) :: Initializers_Boundary_Distribution_Class
     Type (Allocators_Boundary_Distribution_Class)   ,Allocatable :: Allocators
     Type (Initializers_At_Dimension_and_Face_Class) ,Allocatable :: AtDimsAndFaces (:,:)

  END type Initializers_Boundary_Distribution_Class

  TYPE ,PUBLIC ,EXTENDS (Initializer_Base_Class) :: Initializers_At_Dimension_And_Face_Class  

    Class (Allocators_At_Dimension_And_Face_Class) ,Allocatable :: Allocators  
    Class (DataBase_Boundary_Condition_Class)      ,Pointer     :: DataBase 
    Type  (Type_Class)                             ,Allocatable :: BCs (:,:)  
  END type Initializers_At_Dimension_And_Face_Class

This derived types also contains allocatable scalars (Type_Class has them, and DataBase is derived from Type_Class, So it is a bit complex structure for fortran)…

I get this kind of behavior from alot of subroutines, I have only given one of the simplest one as an example, since the total code is very long (tens of thousands of lines).

I hope that in 11.9 this will be corrected.

Thanks in advance…

Hi HeecHee,

This does appear to be a compiler error. Can you please send a report along with the complete code to PGI Customer Service (