Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29251 Discussions

Parameterized Derived Data Type Allocation Error

ScottBoyce
Novice
435 Views

Hi all, the following is a simplified version of a code that I wrote that does not seem to work. For the larger code I just get a generic "compliation error" and then the compiler stops. I tracked that to where I am passing the parameterized derived data type into a subroutine with assumed parameters (eg TYPE (MYTYPE(*,*)),INTENT(INOUT):: TYP). I am not using kind numbers, so I it only contains portions that are defined with LEN in the data type.

 

Below is an example code that results in two different errors:
 

MODULE DT_INTERFACE
    IMPLICIT NONE
    !
    TYPE MAT_TYP(N,M)
        INTEGER,LEN:: N,M
        REAL, DIMENSION(N,N)::A
        REAL, DIMENSION(N,M)::B
        REAL, DIMENSION(M,M)::C        
    END TYPE
    !    
    TYPE MAT_GROUP
        TYPE (MAT_TYP(:,:)),ALLOCATABLE:: MAT
    END TYPE

    TYPE(MAT_GROUP), DIMENSION(:), ALLOCATABLE :: GRP
    
    CONTAINS
! THE FOLLOWING SUBROUTINE IF UNCOMMENTED CAUSE THE MAIN TO CRASH SAYING N AND M ARE ALREADY DEFINED
!
    SUBROUTINE ALLOC_DT(DIM,N,M)
    INTEGER:: DIM, N, M
    INTEGER:: I
    
    ALLOCATE(GRP(DIM))
    
    DO I=1,DIM
      ALLOCATE( MAT_TYP(N,M) :: GRP(I)%MAT )
    END DO
    
    END SUBROUTINE
        
END MODULE
    
PROGRAM MAIN
USE DT_INTERFACE
IMPLICIT NONE
INTEGER:: DIM
INTEGER:: N, M  !IT SEEMS AS IF THESE ARE CONFLICTING WITH THOSE THAT ARE IN THE DATA TYPE
INTEGER:: I

DIM=3
N=3   !IF THESE ARE UNCOMMENTED AN ERROR IS SOMETIMES RAISED SAYING THAT N AND M CAN NOT BE SET AS TEHY ARE LENGTH PROPERTIES
M=4   !THE ERROR IS: "Error	1	 error #6401: The attributes of this name conflict with those made accessible by a USE statement.   	C:\XXX	42	"

!THIS WORKS OVER SUBROUTINE, BUT GRP(1)%MAT%A = 5D0 STILL FAILS
ALLOCATE(GRP(DIM))

DO I=1,DIM
  ALLOCATE( MAT_TYP(N,M) :: GRP(I)%MAT )
END DO

! or if ALLOC_DT is uncommented, then the following could preform the allocation, but causes N and M to crash.
!CALL ALLOC_DT(DIM,N,M)  

!IF I USE THE DEBUGGER AND HAVE A WATCH FOR GRP I CAN SEEE BOTH MAT AND A AS BEING ALLOCATED
!BUT THE FOLLOWING CODE CAUSES A FATAL ERROR IN COMPILATION

GRP(1)%MAT%A = 5D0  !SETTING ARRAY FAILS DUE TO INDEX ERROR

write(*,*)GRP(1)%MAT%A
PAUSE
END PROGRAM
    
    

 

0 Kudos
2 Replies
ScottBoyce
Novice
435 Views

I really wish there is a way to edit a post after its been made. I accidently hit submit instead of preview. The posted program raises an error when GRP(1)%MAT%A is set. Also there is a strange name conflict error when uncommenting CALL ALLOC_DT(DIM,N,M) and then commenting out the allocation part on lines 45 to 50.

0 Kudos
Steven_L_Intel1
Employee
435 Views

Ok, thanks - we'll check it out.

0 Kudos
Reply